kitloong / laravel-migrations-generator Goto Github PK
View Code? Open in Web Editor NEWLaravel Migrations Generator: Automatically generate your migrations from an existing database schema.
License: MIT License
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
License: MIT License
There's a way to generate a migration from *.sql file?
I was reading the documentation, and couldn't an answer for this.
I don't want to generate it from a connection, but from an SQL file, can I do it maybe using one of yours classes?
database.php
'rwsn_sqlsrv' => [ 'driver' => 'sqlsrv', 'url' => env('DATABASE_URL_RWSN_SQLSRV'), 'host' => env('DB_HOST_RWSN_SQLSRV', 'localhost'), 'port' => env('DB_PORT_RWSN_SQLSRV', '1433'), 'database' => env('DB_DATABASE_RWSN_SQLSRV', 'forge'), 'username' => env('DB_USERNAME_RWSN_SQLSRV', 'forge'), 'password' => env('DB_PASSWORD_RWSN_SQLSRV', ''), 'schema' => env('DB_SCHEMA_RWSN_SQLSRV', ''), 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, ],
php artisan migrate:generate -c rwsn_sqlsrv
Using connection: rwsn_sqlsrv
TypeError
MigrationsGenerator\DBAL\Mapper\ViewMapper::makeView(): Argument #2 ($sql) must be of type string, null given, called in /var/www/html/server/niyam/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php on line 60
at vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:77
73▕
74▕ /**
75▕ * @throws \Doctrine\DBAL\Exception
76▕ */
➜ 77▕ private static function makeView(string $name, string $sql): View
78▕ {
79▕ // trim quotes
80▕ $unquotedName = str_replace(['`', '"', '[', ']'], '', $name);
81▕
+3 vendor frames
4 [internal]:0
MigrationsGenerator\DBAL\Schema::MigrationsGenerator\DBAL\{closure}()
+18 vendor frames
23 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Hello,
Current behaviour
When you generate migrations for another connection, and chose to log these migrations in the migrations table, they are logged in the migrations table of the other connection.
Expected behaviour
When you generate migrations for another connection, and chose to log these migrations in the migrations table, they should be logged in the migrations table of the default connection. (This is actually what happens when you run the php artisan migrate
command for a migration related to a connection that is not the default one.)
I use the 7.0 version of laravel/framework.
Thank you!
First, following the installation steps, at the bootstrap/app.php there isn't a line that has $app->withFacades(); commented.
If I add $app->withFacades(); it shows up an error, so if I only add $app->register(\KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider::class); this error shows up:
PHP Fatal error: Uncaught ReflectionException: Class config does not exist in path/to/project/vendor/laravel/framework/src/Illuminate/Container/Container.php:830
Would love to see an option for generating a single file with all migration data. One file per table, and another for foreign keys, is a lot of files!
Looks like provider is not discovered automatically
First of all, you made a great work!
What about a data option? The idea is to add a -d option that permit to generate a migation file with the data present in the table. A suggest wpuld be:
public function up()
{
Schema::create('myTable', function (Blueprint $table) {
$table->id();
// others fields
});
$data = [
["id" => 1, "field_1" => "value_1", /* ...*/ "type" => "field_n" => "value_n"],
["id" => 2, "field_1" => "value_1", /* ...*/ "type" => "field_n" => "value_n"],
/*...*/
["id" => n, "field_1" => "value_1", /* ...*/ "type" => "field_n" => "value_n"]
];
DB::table('myTable')->insert($data);
}
I hope you think it's an interesting idea
This package is awesome, it has saved me a lot of time. I've found a way to make it even better;
I've customized my stubs using Stub Customization: https://laravel.com/docs/7.x/artisan#stub-customization
I noticed that this package seems to ignore my customized stubs.
It would be amazing if this feature could be supported.
Hi
when I use timestamp column in my table and generate migration, I get an error:
TypeError
Argument 1 passed to MigrationsGenerator\Support\Regex::getTextBetween() must be of the type string, null given, called in C:\xampp\htdocs\console\doc\vendor\kitloong\laravel-migrations-generator\src\Mi
grationsGenerator\Generators\Columns\DatetimeColumn.php on line 133
at C:\xampp\htdocs\console\doc\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Support\Regex.php:15
11▕ * @param string $left Left tag.
12▕ * @param string $right Right tag.
13▕ * @return string|null
14▕ */
➜ 15▕ public function getTextBetween(string $text, string $left = '\(', string $right = '\)'): ?string
16▕ {
17▕ $matched = preg_match('/'.$left.'(.*?)'.$right.'/', $text, $output);
18▕ if ($matched === 1) {
19▕ return $output[1];
1 C:\xampp\htdocs\console\doc\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\Columns\DatetimeColumn.php:133
MigrationsGenerator\Support\Regex::getTextBetween()
2 C:\xampp\htdocs\console\doc\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\Columns\DatetimeColumn.php:112
MigrationsGenerator\Generators\Columns\DatetimeColumn::getPgSQLLength("console.apps", Object(Doctrine\DBAL\Schema\Column))
bonjour, lorsque je mets la commande php artisan migrate:generate voici l'erreur affichée (ci-dessous). pouvez vous m'aider ?
de plus dans bootstrap/app.php $app->withFacades(); n'est pas accepté !
Fatal error: Uncaught ReflectionException: Class config does not exist in C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illumin
ate\Container\Container.php:830
Stack trace:
#0 C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illuminate\Container\Container.php(830): ReflectionClass->__construct('config'
)
#1 C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illuminate\Container\Container.php(712): Illuminate\Container\Container->build
('config')
#2 C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(826): Illuminate\Container\Container->re
solve('config', Array, true)
#3 C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illuminate\Container\Container.php(651): Illuminate\Foundation\Application->re
solve('config', Array)
#4 C:\wampServer6 in C:\wampServer64\www\LARAVEL\FdR_TP1_Laravelinititaion\TPJqueryDatatable\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 832
after using the generating command i can't see them into migrations
folder. where are them?
root@8680ab6ed9cd:/var/www# php artisan migrate:generate
Using connection: mysql
Generating migrations for:
Do you want to log these migrations in the migrations table? [Y/n] :
> n
Setting up Tables and Index Migrations
Setting up Foreign Key Migrations
Finished!
migrations
folder is empty. database connection and my .env
file is correct because i'm using that now
I am having the upper mentioned error even after trying multiple time but still it is not working. Anyway, here is the steps I followed and got this error.
First I run this command line.
composer require --dev "kitloong/laravel-migrations-generator"
Then edit app.php file and added the below code to register this.
'providers' => [
..................
\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,
],
Then run the below code as I have many connections to different database in my database.php. MY localhost connection is labeled as localhost also as I want to generate migrations for my localhost database tables only.
php artisan migrate:generate --connection="localhost"
Now after doing all above, I got the below error...
$ php artisan migrate:generate --connection="localhost"
In MigrationsGeneratorSetting.php line 225:
Return value of MigrationsGenerator\MigrationsGeneratorSetting::getTableFilename() must be of the type string, null returned
Trying to istall this package on Laravel Framework 5.8.37 by running
composer require --dev "kitloong/laravel-migrations-generator"
but i've got this:
Using version ^4.3 for kitloong/laravel-migrations-generator
./composer.json has been updated
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
- Conclusion: remove laravel/framework v5.8.37
- Conclusion: don't install laravel/framework v5.8.37
- way/generators 2.0 requires illuminate/support 4.1.* -> satisfiable by illuminate/support[4.1.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9].
- way/generators 2.1 requires illuminate/support 4.1.* -> satisfiable by illuminate/support[4.1.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9].
- way/generators 2.2 requires illuminate/support 4.1.* -> satisfiable by illuminate/support[4.1.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9].
- way/generators 2.3 requires illuminate/support ~4.1 -> satisfiable by illuminate/support[4.1.x-dev, 4.2.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26,
v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- way/generators 2.4 requires illuminate/support ~4.1 -> satisfiable by illuminate/support[4.1.x-dev, 4.2.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26,
v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- way/generators 2.5 requires illuminate/support ~4.1 -> satisfiable by illuminate/support[4.1.x-dev, 4.2.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26,
v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- way/generators 2.6 requires illuminate/support ~4.1 -> satisfiable by illuminate/support[4.1.x-dev, 4.2.x-dev, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26,
v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- way/generators 2.6.1 requires illuminate/support ~4.0 -> satisfiable by illuminate/support[4.0.x-dev, 4.1.x-dev, 4.2.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- don't install illuminate/support 4.1.x-dev|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.0|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.1|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.10|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.11|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.12|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.13|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.14|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.15|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.16|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.17|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.18|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.19|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.2|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.20|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.21|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.22|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.23|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.24|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.25|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.26|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.27|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.28|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.29|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.3|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.30|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.4|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.5|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.6|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.7|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.8|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.1.9|don't install laravel/framework v5.8.37
- don't install illuminate/support 4.2.x-dev|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.0-BETA1|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.1|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.12|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.16|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.17|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.2|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.3|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.4|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.5|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.6|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.7|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.8|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.2.9|don't install laravel/framework v5.8.37
- don't install illuminate/support 4.0.x-dev|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.0|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.0-BETA2|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.0-BETA3|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.0-BETA4|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.1|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.10|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.2|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.3|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.4|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.5|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.6|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.7|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.8|don't install laravel/framework v5.8.37
- don't install illuminate/support v4.0.9|don't install laravel/framework v5.8.37
- Installation request for laravel/framework (locked at v5.8.37, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.37].
- Installation request for way/generators ~2.0 -> satisfiable by way/generators[2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.6.1].
Installation failed, reverting ./composer.json to its original content.
Can procedure support be added? I am sure it will make the project much more useful.
There appears to be a bad assumption made here that just because Laravel maps boolean to MySQL tinyint(1), that ALL occurrences of tinyint(1) in the database should be mapped back to boolean in the migration files.
Tinyints can represent any signed value between -128 and 127, and people use it as such. They should NOT be mapped back to boolean.
Original migration:
Schema::create('voucher', function (Blueprint $table) {
$table->increments('id');
$table->unsignedDecimal('money')->nullable()->virtualAs('`config`->>"$.money"');
$table->json('config')->nullable();
$table->timestamps();
});
To MySQL:
CREATE TABLE `pro_voucher` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`money` decimal(8,2) unsigned GENERATED ALWAYS AS (json_unquote(json_extract(`config`,'$.money'))) VIRTUAL,
`config` json DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
);
Generate:
Schema::create('voucher', function (Blueprint $table) {
$table->increments('id');
$table->decimal('money')->unsigned()->nullable();
$table->json('config')->nullable();
$table->timestamps();
});
This component not support virtual column in mysql. It seem like not easy to implement, but if someone did that will be great!
Would be good to have the option specifying collation and charsets in migrations for DB's that support it eg MySQL. Ideally both at table and column level.
A bool
field in PostgreSQL database with default value doesn't turn to proper migration:
Is:
$table->boolean('create')->default(''); // when default is false
$table->boolean('create')->default('1'); // when default is true
Should be:
$table->boolean('create')->default(false); // when default is false
$table->boolean('create')->default(true); // when default is true
When trying to generate a migration for a table in the non-default connection no output is generated.
I am trying to generate migrations from an AWS Redshift database. Regular queries on a separate connection (named redshift
) execute without issue. When I specify that connection for this command, nothing gets written to disk.
The one clue I have to go on is that no tablename is shown in the message that gets output. There are strings of text that should contain table names, but they are empty
Hello,
while trying to generate migrations i got an error
Undefined property: stdClass::$Type at D:\Dev\wikitaf\vendor\kitloong\laravel-migrations generator\src\KitLoong\MigrationsGenerator\Repositories\MySQLRepository.php:22
The problem seems to be the Type
property on MySQLRepository::getSetPresetValues
and MySQLRepository::getEnumPresetValues
Replacing by type
(without uppercase) works fine for me.
package version : "^4.4",
vendor/kitloong/laravel-migrations-generator/src/KitLoong/MigrationsGenerator/MigrationsGeneratorSetting.php:63
protected function getDoctrineDriver()
64| {
65| if (! class_exists(DoctrineDriver::class)) {
66| throw new LogicException(
67| 'Laravel v6 is only compatible with doctrine/dbal 2, in order to use this feature you must require the package "doctrine/dbal:^2.6".'
68| );
69| }
This is not an issue.
I want to know, if its possible thru this package to sync my migration or generate new migrations when i add or remove (colomn or row of table) in the database?
Ran this command after installing the package:
php artisan migrate:generate -c pgsql
We have custom data type for some columns in postgres 13.
example:
create type phone_number_type as enum ('TOLL-FREE', 'SHORTCODE', '10 DLC', 'ALPHANUMERIC', 'TOLLFREE');
Then used in table like this:
create table phone_numbers
(
id bigserial
constraint phone_numbers_pk primary key,
phone varchar(60),
type phone_number_type,
);
This package gives following error during migration generate:
After composer install when run php artisan:migrate returns error :
PHP Fatal error: Uncaught ReflectionException: Class config does not exist in Container.php:805
Laravel 7 (current version Jun - 2020)
Composer 1.10.7
How do I register for the service? Not for direct use
Hi, first of all I want to thank you for this awesame package!!
I have a small issue when running a command with the --path option and it always throws the following error:
php artisan migrate:generate --path="testing"
ErrorException
file_put_contents(./testing/2021_02_10_170030_create_accion_comparables_table.php): failed to open stream: No such file or directory
at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:135
My goal is to create the migrations on a different folder than migrations, it can be a subfolder as well, do you know if i´m doing something wrong?
Thanks in advance,
Alejandro
Illuminate\Database\QueryException
SQLSTATE[42703]: Undefined column: 7 ERROR: column pgc.consrc does not exist
LINE 7: pgc.consrc AS definition
^
HINT: Perhaps you meant to reference the column "pgc.conkey" or the column "pgc.conbin". (SQL:
SELECT pgc.conname AS constraint_name,
pgc.contype,
ccu.table_schema AS table_schema,
ccu.table_name,
ccu.column_name,
pgc.consrc AS definition
FROM pg_constraint pgc
JOIN pg_namespace nsp ON nsp.oid = pgc.connamespace
JOIN pg_class cls ON pgc.conrelid = cls.oid
LEFT JOIN information_schema.constraint_column_usage ccu
ON pgc.conname = ccu.constraint_name
AND nsp.nspname = ccu.constraint_schema
WHERE contype ='c'
AND ccu.table_name='pgsql_radreplies'
AND ccu.column_name='username';
)
Hi,
I'm on laravel 6 and after installing the package with composer and running php artisan migrate:generate
i get this error
Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to MigrationsGenerator\MigrationsGeneratorSetting::setTableFilename() must be of the type string, null given, called in C:\lar agon\www\erp\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\MigrateGenerateCommand.php on line 116
Database connection: pgsql
In the following scenario-
create type my_status as enum ('PENDING', 'ACTIVE', 'SUSPENDED');
create table mydb.mytable
(
...
status my_status not null,
...
);
getting the following exception-
Unknown database type my_status requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.
~\vendor\doctrine\dbal\src\Platforms\AbstractPlatform.php:394
Laravel 8, php 7.3.7, laravel-migrations-generator 5.1, MySQL MariaDB 10.2 image from docker
Error thrown on php artisan migrate:generate
php artisan migrate:generate
Error
Call to private Doctrine\DBAL\Types\Type::__construct() from context 'MigrationsGenerator\DBAL\Schema'
at vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Schema.php:220
216▕ * @throws \Doctrine\DBAL\Exception
217▕ */
218▕ protected function registerCustomDoctrineType(string $dbType, string $class): void
219▕ {
➜ 220▕ $doctrineType = (new $class())->getName();
221▕ if (!Type::hasType($doctrineType)) {
222▕ Type::addType($doctrineType, $class);
223▕ } else {
224▕ Type::overrideType($doctrineType, $class);
+15 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Generate migrations for my database
[2022-01-24 20:35:14] local.ERROR: Call to private Doctrine\DBAL\Types\Type::__construct() from context 'MigrationsGenerator\DBAL\Schema' {"exception":"[object] (Error(code: 0): Call to private Doctrine\\DBAL\\Types\\Type::__construct() from context 'MigrationsGenerator\\DBAL\\Schema' at /app/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Schema.php:220)
[stacktrace]
#0 /app/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Schema.php(91): MigrationsGenerator\\DBAL\\Schema->registerCustomDoctrineType('double', 'MigrationsGener...')
#1 /app/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/MigrateGenerateCommand.php(79): MigrationsGenerator\\DBAL\\Schema->initialize()
#2 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): MigrationsGenerator\\MigrateGenerateCommand->handle()
#3 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#4 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#5 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#6 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#7 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#8 /app/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#9 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#10 /app/vendor/symfony/console/Application.php(1005): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#11 /app/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(MigrationsGenerator\\MigrateGenerateCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#12 /app/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#13 /app/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 /app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 {main}
"}
Great module, really useful thank you.
A Full Text index though is created as a regular index which throws an error when trying to index a TEXT field
Not sure if laravel has a method so I normally create a direct command to make them:-
DB::statement('ALTER TABLE
faqsADD FULLTEXT
full_text (
question,
answer);');
I have the an error when i run php artisan migrate:generate
error info: Argument 1 passed to Doctrine\DBAL\Connection::ensureForwardCompatibilityStatement() must be an instance of Doctrine\DBAL\Driver\ResultStatement, instance of PDOStatement given, called in myproject\ven
dor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php on line 1313, anyone konw How to solve it?
Thanks for the package and keep it maintained
In postgres sql, currently array of integer is mapped to integer,
may i know why it was mapped to integer, even if it's updated to text it was fine, but why as integer? any particular reason for that,
though if i want to change the mapping to text how could i do that? any config changes need to applied
Since version 5, we are getting RAM-related errors because the tool is trying to instantiate a Table
class for each table in our database. Normally, I guess, that should not be a problem. But we have some databases with more than 50k tables and views.
I'm specifying which tables should be generated (less than 100), but I noticed in the code of the tool that it first (1) gets the names of all the tables of the database, then (2) it gets the "details" of each of them, one by one, and finally (3) it filters the tables according to what we specify in the command's parameters.
Shouldn't step 3 happen before step 2 so it only the details of the tables we specified?
In version 4, we didn't have this problem.
For reference, this is the method that does the "get the tables and filter them" job.
We have a lot of tables, each of which contain multiple foreign keys.
Right now this generator generates separate migrations for creating the table and adding keys.
I want just one migration that fully creates the table.
It will be awesome if have support to generating view and trigger from database.
I already have sample of those migration that already working in my project.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTriggerDomainInsert extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::getPdo()->exec('
CREATE TRIGGER domain_insert AFTER INSERT ON numbers FOR EACH ROW
INSERT INTO number_domain_history (number_id, domain_name, date) VALUES (NEW.id, NEW.domain, NOW())
');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::getPdo()->exec('DROP TRIGGER `domain_insert`');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateViewNumberReport extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement("DROP VIEW IF EXISTS number_contact_report_view");
DB::statement("
CREATE VIEW number_contact_report_view AS (
SELECT
users.name AS user_name,
cl.date,
SUM(cl.deposit_amount) AS sum_deposit_amount,
COUNT(contact_status_destination_id) AS total_status,
CASE WHEN contact_status_destination_id = 1 THEN COUNT(contact_status_destination_id) END AS not_interested,
CASE WHEN contact_status_destination_id = 2 THEN COUNT(contact_status_destination_id) END AS interested,
CASE WHEN contact_status_destination_id = 3 THEN COUNT(contact_status_destination_id) END AS registered,
CASE WHEN contact_status_destination_id = 4 THEN COUNT(contact_status_destination_id) END AS success,
CASE WHEN contact_status_destination_id = 5 THEN COUNT(contact_status_destination_id) END AS trash
FROM contact_logs AS cl
LEFT JOIN contact_status AS cs ON cs.id = cl.contact_status_destination_id
LEFT JOIN users ON users.id = cl.user_id
GROUP BY user_name, contact_status_destination_id, cl.date
)
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement("DROP VIEW IF EXISTS number_contact_report_view");
}
}
DB: postgres
Existing table structure:
Column | Type | Collation | Nullable | Default |
---|---|---|---|---|
created_at | timestamp(0) without time zone | not null | now() | |
updated_at | timestamp(0) without time zone | not null | now() |
Generated table structure:
Column | Type | Collation | Nullable | Default |
---|---|---|---|---|
created_at | timestamp(0) without time zone | not null | '2021-06-21 19:30:05.997451'::timestamp without time zone | |
updated_at | timestamp(0) without time zone | not null | '2021-06-21 19:30:05.997451'::timestamp without time zone |
Generated migration:
Schema::create('tabkeName', function (Blueprint $table) {
$table->timestamp('created_at')->default('now()');
$table->timestamp('updated_at')->default('now()');
});
MySQL 8 is already here, it would be awesome If it was supported, I do not know if is the version but I couldn't make migration from MySQL 8, it works perfectly from a Seventh version.
If I already have 10 migrations but I want to regenerate all according to the database so when I setup new env to be ready but also want to not screw up the production database?
php artisan migrate:generate --tables= "table1,table2"
TypeError
Argument 1 passed to MigrationsGenerator\MigrationsGeneratorSetting::setTableFilename() must be of the type string, null given, called in /home/username/Projects/project_name/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/MigrateGenerateCommand.php on line 123
at vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/MigrationsGeneratorSetting.php:233
229▕
230▕ /**
231▕ * @param string $tableFilename
232▕ */
➜ 233▕ public function setTableFilename(string $tableFilename): void
234▕ {
235▕ $this->tableFilename = $tableFilename;
236▕ }
237▕
+15 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Hi
Installed on Laravel 8 with an SQL server I keep getting the following error when trying to generate migrations.
Unknown database type xml requested, Doctrine\DBAL\Platforms\SQLServer2012Platform may not support it.
Any assistance would be appreciated. Thanks
Heya and thanks for this awesome piece of code!
We have one issue: We're using Laravel Forge or Deployer (both pull the code from a git repo on the remote server) in our projects and this leads to errors when we ran the migrations generator locally, commit and push the changes and then deploy.
Because the remote server does not have the locally generated entries for the new migrations in the migrations
table, the required php artisan migrate command fails (SQLSTATE[42S01]: Base table or view already exists
).
Any idea how to work around this issue?
Thanks in advance!
Pelle
Please, how can I generate migrations from a SQLite database ?
I installed the package, but when I run the command php artisan migrate:generate
, I get this error: Undefined index: SQLite
CREATE TABLE `users` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '姓名1,
`created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
$ php artisan migrate:generate users
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id')->comment('ID');
$table->timestamps()->comment('更新时间');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
$table->timestamps()->comment('更新时间');
This line raises an error while performing the migration.Because it has no comment method.Hope you can help, thank you very much!
The package generates a migration file with spatial indexes and passes an index name as a parameter, although spatialIndex
shouldn't receive any parameters.
<?php
// Current:
$table->point('location')->spatialIndex('apartments_location_spatial');
// Should be:
$table->point('location');
$table->spatialIndex('location', 'apartments_location_spatial');
is there any way how to generate incremental changes only ?
I'm getting an Type enum already exists
exception when trying to execute migrate:generate
and don't fully understand, what I'm missing here. See (truncated) stacktrace below.
php artisan migrate:generate -vvv
Using connection: mysql
Doctrine\DBAL\DBALException
Type enum already exists.
at vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:254
250| * @return \Doctrine\DBAL\DBALException
251| */
252| public static function typeExists($name)
253| {
> 254| return new self('Type ' . $name . ' already exists.');
255| }
256|
257| /**
258| * @param string $name
1 vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/TypeRegistry.php:68
Doctrine\DBAL\DBALException::typeExists("enum")
2 vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Type.php:246
Doctrine\DBAL\Types\TypeRegistry::register("enum", Object(KitLoong\MigrationsGenerator\Types\EnumType))
3 vendor/kitloong/laravel-migrations-generator/src/KitLoong/MigrationsGenerator/Generators/SchemaGenerator.php:90
Doctrine\DBAL\Types\Type::addType("enum", "KitLoong\MigrationsGenerator\Types\EnumType")
4 vendor/kitloong/laravel-migrations-generator/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php:132
KitLoong\MigrationsGenerator\Generators\SchemaGenerator::initialize("mysql")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.