Coder Social home page Coder Social logo

xethron / migrations-generator Goto Github PK

View Code? Open in Web Editor NEW
3.3K 114.0 591.0 102 KB

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

License: MIT License

PHP 100.00%
laravel-migration php existing-database

migrations-generator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

migrations-generator's Issues

Prefix is not properly detected

DB prefix is set in the settings, but exported migrations keep the prefix text on the table names, causing the table name to be incorrect when you later import it (creates prefix_prefix_tablename)

The requested package way/generators could not be found in any version

Error when using composer update on laravel v5.1.17:

Problem 1
- The requested package way/generator could not be found in any version, there may be a typo in the package name.
Problem 2
- Installation request for xethron/migrations-generator dev-l5 -> satisfiable by xethron/migrations-generator[dev-l5].
- xethron/migrations-generator dev-l5 requires way/generators dev-feature/laravel-five-stable -> no matching package found.

Failed to clone [email protected]:jamisonvalenta/Laravel-4-generators.git, git was not found

I'm getting this error. I should have no typos. Everything is copied directly from the readme.

[RuntimeException]
Failed to clone [email protected]:jamisonvalenta/Laravel-4-generators.git, git was not found, check that it is installed and in your PATH env.
'git' is not recognized as an internal or external command,
operable program or batch file.

"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.
|3.0.",
"symfony/dom-crawler": "2.8.
|3.0.*",
"xethron/migrations-generator": "dev-l5",
"way/generators": "dev-feature/laravel-five-stable" },

"repositories": {
"repo-name": {
"type": "git",
"url": "[email protected]:jamisonvalenta/Laravel-4-generators.git"
}

Xethron/migrations-generator could not be found

"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.
|3.0.",
"symfony/dom-crawler": "2.8.
|3.0.*",
"xethron/migrations-generator": "dev-15",
"way/generators": "dev-feature/laravel-five-stable"
},

"repositories": {
"repo-name": {
"type": "git",
"url": "[email protected]:jamisonvalenta/Laravel-4-generators.git"
}
}

in my composer.json, I receive the error

"Xethron/migrations-generator could not be found or there is a typo"

I have followed the instructions to the letter on the library home page.

Double converted to float(10,0)

Hi,
I've just tested your generator and its working pretty well. I just noticed that double columns are converted to float(10,0). Is this behaviour intended?

Greets

Issue with octobercms

I added some custom tables to my octobercms database and would like to generate a model from these tables, using this generator + https://packagist.org/packages/user11001/eloquent-model-generator

Now if I fire "php artisan migrate:generate" or even "php artisan help", the following error will appear:

[ErrorException]
Argument 5 passed to Xethron\MigrationsGenerator\MigrateGenerateCommand::__construct() must be an instance of Illuminate\Config\Repository, i
nstance of October\Rain\Config\Repository given, called in vendor/xethron/migrations-generator/src/Xethron/MigrationsGe
nerator/MigrationsGeneratorServiceProvider.php on line 30 and defined

Any idea how to fix this? Is it possible to use this within a OctoberCMS installation or have a setup another laravel environment for this migration first, and then put it manually it octobercms?

thx for help.

Export should account for the prefix

The export process grabs the tables exactly as they are in the db. So, if you have a prefix set, when you run the migration again you'll have prefix__prefix__tablename which breaks all kinds of stuff.

Since the prefix is set on the database configuration, it should be removed from the table names when exporting.

Can it generate migrations for updates since the last generation?

Lets say I'm constructing db structure from EER diagram. Creating, updating, etc. Suppose I generated initial set of migrations. What happens if I change db structure as usually from EER diagram. Will it be able to detect the fact and create migration for changes only?

Laravel 5.1

Is the installation procedure for the generator the same as Laravel 5? Or do the tools need to be updated to this version. I get a "Class 'Way\Generators\GeneratorServiceProvider' not found" exception when trying to run artisan.

enum support?

I'm running into this error:

[Doctrine\DBAL\DBALException]                                                
  Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform  
   may not support it.              

My tables have enum() types.

In PostgreSQL certain tables contain double quotes when listTableNames() is called

Hi,

when $this->schema->listTableNames(); is called some table names are enclosed by double quotes.
For example table names like "order" or "user"
I know this could be more an issue of doctrine than yours, however i modified the getTables function...

public function getTables()
    {
        $tables = $this->schema->listTableNames();
        if (is_array($tables))
        {
            for ($i = 0; $i < count($tables); $i++)
            {
                if (preg_match('/"/', $tables[$i]))
                {
                    $tables[$i] = str_replace('"', '', $tables[$i]);
                }
            }
        }
        return $tables;
    }

Support for calling migrate:generate in application.

I am looking to use this package in the application as such: Artisan::call('migrate:generate');. The interactive questions however limit me from doing so.

I'd like to propose integrating support for the --no-interaction option and falling back to the default values for this.

error on install of dev-master on windows 7

Ran composer update with "xethron/migrations-generator": "dev-master"
in composer.json and got this error:

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'IlluXethron\MigrationsGenerator\MigrationsGeneratorServiceProviderminate\Workbench\WorkbenchServiceProvider' not found","file":"C:\Users\norm\trivia\bootstrap\compiled.php","line":4219}}Script php artisan clear-compiled handling the post-update-cmd event returned with an error

Problem may be that the namespace statement is on the same line as the php header in MigrationsGeneratorServiceProvider.php. It may not have been caught on linux but Windows may be sensitive to this:

Is this work for SQL SERVER

I have application using C# and SQL server , now i want to generate model from SQL Server exists database and re-create on MySQL, is this work for SQL Server?
Thanks

ForeignKeys migrations: drop issue

When generating the dropForeign, laravel asks for the index name. The package is using the field name.

Having this up():

Schema::table('A', function(Blueprint $table)
{
$table->foreign('B_id', 'A_B_id_fkey')->references('id')->on('B')->onUpdate('RESTRICT')->onDelete('RESTRICT');
});

Generates this down:

Schema::table('A', function(Blueprint $table)
{
$table->dropForeign('B_id');
});

Should generate:

Schema::table('A', function(Blueprint $table)
{
$table->dropForeign('A_B_id_fkey');
});

Tests trying to create a table twice

We have the following migration and when we run tests they fail because

PDOException: SQLSTATE[HY000]: General error: 1 there is already a table named block

Here's the migration:

        public function up()
        {
            Schema::create('block', function(Blueprint $table)
            {
                $table->increments('block_id');
                    $table->string('field')->default('')->index('field');
                $table->string('operator', 6)->default('')->index('operator');
                $table->string('block')->default('')->index('block');
                $table->integer('weight')->unsigned()->nullable()->default(1)->index('weight');
                $table->string('added_by', 16)->nullable();
                $table->timestamp('ts')->default(DB::raw('CURRENT_TIMESTAMP'));
            });
        }

I removed the index->() calls and the error went away.

Let me know what other info i can provide that might be of help.

Postgres UUID columns are generated as $table->guid

Postgres UUID columns are generated as $table->guid, resulting in

PHP Fatal error: Call to undefined method Illuminate\Database\Schema\Blueprint::guid()

The right method name is Blueprint::uuid(), so it's temporarily fixed by a replace.
Used versions: Laravel 5.2.10, PostgreSQL 9.3

Undefined index: index_type

I got "Undefined index: index_type" error. I followed these steps. I dont know why I got this error.

root@user-System-Product-Name:/var/www/x# php artisan migrate:generate
Using connection: mysql

Generating migrations for: x, y, z, Etc

Do you want to log these migrations in the migrations table? [Y/n] :

Y

Next Batch Number is: 1. We recommend using Batch Number 0 so that it becomes the "first" migration [Default: 0] :

0
Setting up Tables and Index Migrations

[ErrorException]
Undefined index: index_type

JSON datatype not handled for PostgreSQL

I'm using PostgreSQL and I have two tables with a JSON datatype. When generating migrations it throws the error "Unknown database type json requested, Doctrine\DBAL\Platforms\PostgresqlPlatform may not support it".

I fixed it by adding:

$connection->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'string');

to \Xethron\MigrationsGenerator\Generators\SchemaGenerator in the constructor

Problem on composer update

Problem

When running composer update.

Problem 1
    - Installation request for xethron/migrations-generator dev-master -> satisfiable by xethron/migrations-generator[dev-master].
    - xethron/migrations-generator dev-master requires way/generators 2.* -> no matching package found.

Fixed

I had "way/generators": "dev-master" installed.

Thanks for the script.

Unsupported operand types error with --ignore option

Any ideas? Works without --ignore option.

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Unsupported operand types","file":"...../vendor/xethron/migrations-generator/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php","line":145}}

artisan error message: classes not found

I followed the instructions on the readme homepage: put the file in composer.json, ran composer update, and got the Way and Xethron PHP libraries put in my vendor dir, and added the two lines of services providers to the providers array in config/app.php. When I try and run "php artisan migrate:generate," I get the following error message:

C:\xampp\htdocs\workflow>php artisan migrate:generate
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","me
ssage":"Class 'Way\Generators\GeneratorsServiceProvider' not found","file":"C:
\xampp\htdocs\workflow\vendor\laravel\framework\src\Illuminate\Foundati
on\ProviderRepository.php","line":123}}{"error":{"type":"Symfony\Component\De
bug\Exception\FatalErrorException","message":"Class 'Way\Generators\Generato
rsServiceProvider' not found","file":"C:\xampp\htdocs\workflow\vendor\larav
el\framework\src\Illuminate\Foundation\ProviderRepository.php","line":123}}

How do I fix this?

boolean field is not migrated properly

I have a table with boolean field with default value set as false. When I run migration it shows
$table->boolean('deleted')->default('');
default is shown as null field. Can you please check and let me know a solution for same

Package not found [solved]

The requested package way/generators dev-feature/laravel-five-stable exists as way/generators[1.0, 1.1, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.6.1, 3, 3.0.1, 3.0.2, 3.0.3, dev-master, dev-rewrite] but these are rejected by your constraint.

Pulling in way/generators:dev-master does work but then the migrations-generator fails with

" - Installation request for xethron/migrations-generator dev-l5 -> satisfiable by xethron/migrations-generator[dev-l5].
- xethron/migrations-generator dev-l5 requires way/generators dev-feature/laravel-five-stable -> no matching package found"

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for xethron/migrations-generator dev-master -> satisfiable by xethron/migrations-generator[dev-master].
- xethron/migrations-generator dev-master requires way/generators 2.* -> no matching package found.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

In my composer file:
"require-dev": {
"way/generators": "~3.0",
"xethron/migrations-generator": "dev-master"
}

Stored Procedure Migration

Hi guys,

Sorry if I ask a stupid question, but is it possible in this migration generator that the stored procedure get migrated out as well?

Does not make "generate" functions compatible with L5

Although this adds the "generate" functions to artisan, they do not work with Laravel 5, only migrate:generate has been made to work with L5. Perhaps a note stating this in the readme would be useful.

Updated: It seems as though some of the generate functions do work as expected, resource for example. scaffold does not however.

Lumen

Hi there,

Is it possible to have migrations-generator in Lumen too?

trying to use it in Lumen but failed.

migrations-generator-error

Here my composer.json looks like

composer json

Unsigned increments('id) takes as increments('id)

Hi,
very useful package! :)

I found this issue: when generating migrations of tables with an unsigned increments('column'), the unsigned part is not taken.
To be some specific, if we take a table created with:

Schema::create('tb_users_assigned_roles', function($table)
    {
        $table->increments('id')->unsigned();
        $table->integer('user_id')->unsigned();
        $table->integer('role_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('tb_users');
        $table->foreign('role_id')->references('id')->on('roles');
    });

migrations-generator creates the following migration:

Schema::create('tb_users_assigned_roles', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('user_id')->unsigned()->index('`assigned_roles_user_id_foreign`');
        $table->integer('role_id')->unsigned()->index('`assigned_roles_role_id_foreign`');
    });

that is, the ->unsigned(); part of the first column is lost.

If I find other problems, I'll report them!

Make all tables innodb?

Hey, could you make an option so we could make it generate all inno db tables? You really just need to make it add the line $table->engine = "InnoDB"; to each create file, and I looked through it but I just couldn't find where I would make changes to make this possible.

Foreign Keys and Cascades

Hi,
migrations for foreign keys are properly generated but those cascades like "onDelete" won't be added to the migrations.

Migrations attempt to create indices twice.

I have the following line in a generated migration:

$table->float('more_than', 10, 0)->default(25)->index('`more_than`');

Which is in turn generating the following error:

[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1 index more_than already exists (SQL: create index `more_than` on "discounts" ("more_than"))

Moving the index step to its own line (and removing the backticks, ha ha) works fine:

$table->index('more_than');

But the following line works just fine (backticks and all):

$table->enum('shipmethod', array('1', '2', '3', '4', '5', '6', '7'))->default('1')->index('`shipmethod`');

Error on add_foreign_key_to_

When the app create the file add_foreign_key_to_TABLE creates as an example:

up() Method: $table->foreign('account', 'account_fi1kk')->references('number')->on('accounts');
down() Method: $table->dropForeign('account');

Down method isn't correct in laravel 4, must be $table->dropForeign('account_fi1kk'); if not is not possible to rollback because laravel returns an General error: 1025 Error on rename of table because can't remove foreign key

php artisan migrate:generate json type was unsupported.

php artisan migrate:generate

[Doctrine\DBAL\DBALException]
Unknown database type json requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

Didn`t support type json ,my database is mysql version >=5.7 .

Column name with reserved character generates incorrect migration

Supposing you have this:

mysql> create table test (`foo.bar` int);
Query OK, 0 rows affected (0.05 sec)

mysql> describe test;
+---------+---------+------+-----+---------+-------+
| Field   | Type    | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| foo.bar | int(11) | YES  |     | NULL    |       |
+---------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)

Then the generated migration $table->integer('foo.bar')->nullable(); is incorrect: Eloquent explodes that to a table name and column, that is this incorrect SQL:

create table test (`foo`.`bar` int);  /* oops, no table `foo` */

The proper generation should be:

$table->integer(DB::raw('`foo.bar`')->nullable();

where both the list of reserved characters and the escape character is driver-specific. The patch for this seems straightforward: if the column name contains a driver-specific reserved character, wrap the generation in a DB::raw using the driver-specific escape character. Possibly an even simpler solution is to wrap ALL column names in DB::raw...

P.S.: I'm not saying a column like this is a good idea! I did just encounter it, though, reversing a legacy system.

Backticks around index names are MySQL specific

The generated migrations have backticks in the index names, like this:

$table->integer('affiliate_id')->index('`affiliate_actions_affiliate_id`');

These cause errors in PostgreSQL, as the backtick character is not ANSI SQL, and is specific to MySQL only.

Error text in console from Artisan:

  [Illuminate\Database\QueryException]
  SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "`"
  LINE 1: create index `admins_user_id` on "admins" ("user_id")
                       ^ (SQL: create index `admins_user_id` on "admins" ("user_id"))

Index names without the backticks works fine, however:

$table->integer('affiliate_id')->index('affiliate_actions_affiliate_id');

laravel 5 not install

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for xethron/migrations-generator dev-l5 -> satisfiable by xethron/migrations-generator[dev-l5].
- xethron/migrations-generator dev-l5 requires way/generators dev-feature/laravel-five-stable -> no matching package found.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

unique colums are not unique after generation

The generate operation doesn't keep the columns unique, the unique option seems to be completely ignored. I have only indexed unique columns in the table I've experienced the issue with - the indexes are exported correctly, but the unique option is gone after generation.

before:

$table->string('xx');
$table->index('xx');
$table->unique('xx');`

after:

$table->string('xx')->index();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.