File tree 6 files changed +70
-14
lines changed 6 files changed +70
-14
lines changed Original file line number Diff line number Diff line change 2
2
3
3
return [
4
4
// Where the templates for the generators are stored.
5
- 'migration_template_path ' => __DIR__ . '/../stubs/migration.generate.stub ' ,
5
+ 'migration_template_path ' => __DIR__ . '/../stubs/migration.generate.stub ' ,
6
+ 'migration_anonymous_template_path ' => __DIR__ . '/../stubs/migration.generate.anonymous.stub ' ,
6
7
7
8
// Where the generated files will be saved.
8
- 'migration_target_path ' => base_path ('database/migrations ' ),
9
+ 'migration_target_path ' => base_path ('database/migrations ' ),
9
10
10
11
// Migration filename pattern.
11
- 'filename_pattern ' => [
12
+ 'filename_pattern ' => [
12
13
'table ' => '[datetime]_create_[name]_table.php ' ,
13
14
'view ' => '[datetime]_create_[name]_view.php ' ,
14
15
'procedure ' => '[datetime]_create_[name]_proc.php ' ,
Original file line number Diff line number Diff line change 22
22
use KitLoong \MigrationsGenerator \Schema \Schema ;
23
23
use KitLoong \MigrationsGenerator \Schema \SQLiteSchema ;
24
24
use KitLoong \MigrationsGenerator \Schema \SQLSrvSchema ;
25
+ use KitLoong \MigrationsGenerator \Support \CheckMigrationMethod ;
25
26
26
27
class MigrateGenerateCommand extends Command
27
28
{
29
+ use CheckMigrationMethod;
30
+
28
31
/**
29
32
* The name and signature of the console command.
30
33
*
@@ -148,9 +151,7 @@ protected function setup(string $connection): void
148
151
$ this ->option ('path ' ) ?? Config::get ('migrations-generator.migration_target_path ' )
149
152
);
150
153
151
- $ setting ->setStubPath (
152
- $ this ->option ('template-path ' ) ?? Config::get ('migrations-generator.migration_template_path ' )
153
- );
154
+ $ this ->setStubPath ($ setting );
154
155
155
156
$ setting ->setDate (
156
157
$ this ->option ('date ' ) ? Carbon::parse ($ this ->option ('date ' )) : Carbon::now ()
@@ -173,6 +174,25 @@ protected function setup(string $connection): void
173
174
);
174
175
}
175
176
177
+ /**
178
+ * Set migration stub.
179
+ *
180
+ * @param \KitLoong\MigrationsGenerator\Setting $setting
181
+ * @return void
182
+ */
183
+ protected function setStubPath (Setting $ setting ): void
184
+ {
185
+ $ defaultStub = Config::get ('migrations-generator.migration_anonymous_template_path ' );
186
+
187
+ if (!$ this ->hasAnonymousMigration ()) {
188
+ $ defaultStub = Config::get ('migrations-generator.migration_template_path ' );
189
+ }
190
+
191
+ $ setting ->setStubPath (
192
+ $ this ->option ('template-path ' ) ?? $ defaultStub
193
+ );
194
+ }
195
+
176
196
/**
177
197
* Get all tables from schema or return table list provided in option.
178
198
* Then filter and exclude tables in `--ignore` option if any.
Original file line number Diff line number Diff line change 2
2
3
3
namespace KitLoong \MigrationsGenerator \Support ;
4
4
5
+ use Illuminate \Database \Migrations \Migrator ;
5
6
use Illuminate \Database \Schema \Blueprint ;
6
7
use Illuminate \Database \Schema \Grammars \Grammar ;
7
8
@@ -38,4 +39,15 @@ public function hasFullText(): bool
38
39
{
39
40
return method_exists (Grammar::class, 'compileFulltext ' );
40
41
}
42
+
43
+ /**
44
+ * Check if support anonymous migration.
45
+ * This feature is added in late Laravel v8 and above.
46
+ *
47
+ * @return bool
48
+ */
49
+ public function hasAnonymousMigration (): bool
50
+ {
51
+ return method_exists (Migrator::class, 'getMigrationClass ' );
52
+ }
41
53
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ {{ use }}
4
+
5
+ return new class extends Migration
6
+ {
7
+ /**
8
+ * Run the migrations.
9
+ *
10
+ * @return void
11
+ */
12
+ public function up()
13
+ {
14
+ {{ up }}
15
+ }
16
+
17
+ /**
18
+ * Reverse the migrations.
19
+ *
20
+ * @return void
21
+ */
22
+ public function down()
23
+ {
24
+ {{ down }}
25
+ }
26
+ };
Original file line number Diff line number Diff line change @@ -144,8 +144,7 @@ protected function generateMigrations(array $options = []): void
144
144
$ this ->artisan (
145
145
'migrate:generate ' ,
146
146
array_merge ([
147
- '--path ' => $ this ->getStorageMigrationsPath (),
148
- '--template-path ' => base_path ('stubs/migration.generate.stub ' ),
147
+ '--path ' => $ this ->getStorageMigrationsPath (),
149
148
], $ options )
150
149
)
151
150
->expectsQuestion ('Do you want to log these migrations in the migrations table? ' , true )
Original file line number Diff line number Diff line change @@ -63,9 +63,8 @@ public function testDBConnection()
63
63
$ this ->artisan (
64
64
'migrate:generate ' ,
65
65
[
66
- '--connection ' => 'mysql57 ' ,
67
- '--path ' => $ this ->getStorageMigrationsPath (),
68
- '--template-path ' => base_path ('stubs/migration.generate.stub ' ),
66
+ '--connection ' => 'mysql57 ' ,
67
+ '--path ' => $ this ->getStorageMigrationsPath (),
69
68
]
70
69
)
71
70
->expectsQuestion ('Do you want to log these migrations in the migrations table? ' , true )
@@ -101,9 +100,8 @@ public function testLogMigrationToAnotherSource()
101
100
$ this ->artisan (
102
101
'migrate:generate ' ,
103
102
[
104
- '--connection ' => 'mysql57 ' ,
105
- '--path ' => $ this ->getStorageMigrationsPath (),
106
- '--template-path ' => base_path ('stubs/migration.generate.stub ' ),
103
+ '--connection ' => 'mysql57 ' ,
104
+ '--path ' => $ this ->getStorageMigrationsPath (),
107
105
]
108
106
)
109
107
->expectsQuestion ('Do you want to log these migrations in the migrations table? ' , true )
You can’t perform that action at this time.
0 commit comments