Skip to content

Commit 124a5be

Browse files
authored
Merge pull request #129 from kitloong/feature/procedure
Generate store procedures
2 parents fc37c5e + 1bf3fb3 commit 124a5be

File tree

124 files changed

+2215
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2215
-1020
lines changed

.gitattributes

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
33

44
# Ignore all test and documentation with "export-ignore".
5-
/.github export-ignore
6-
/tests export-ignore
7-
/.editorconfig export-ignore
8-
/.env.* export-ignore
9-
/.gitattributes export-ignore
10-
/.gitignore export-ignore
11-
/.phpmd.xml export-ignore
12-
/phpcs.xml export-ignore
13-
/phpstan.neon export-ignore
14-
/phpunit.xml export-ignore
15-
/testbench.yaml export-ignore
5+
/.github export-ignore
6+
/tests export-ignore
7+
/.editorconfig export-ignore
8+
/.env.* export-ignore
9+
/.gitattributes export-ignore
10+
/.gitignore export-ignore
11+
/.phpmd.xml export-ignore
12+
/check_migrations.sh export-ignore
13+
/phpcs.xml export-ignore
14+
/phpstan.neon export-ignore
15+
/phpunit.xml export-ignore
16+
/phpunit8.xml export-ignore
17+
/testbench.yaml export-ignore

.github/workflows/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ jobs:
106106
laravel: 8.*
107107
dbal: 3.*
108108
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2
109+
- php: 8.2
110+
laravel: 9.*
111+
dbal: 3.*
112+
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2
113+
- php: 8.2
114+
laravel: 8.*
115+
dbal: 3.*
116+
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2
109117

110118
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
111119

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.phpstorm.meta.php
1212
.phpunit.result.cache
1313
_ide_helper.php
14+
check_migrations.sh
1415
docker-compose.yml
1516
composer.lock
1617
coverage.xml

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Laravel Migrations Generator
22

33
![Style check CI](https://github.com/kitloong/laravel-migrations-generator/actions/workflows/check.yml/badge.svg?branch=6.x)
4-
[![codecov](https://codecov.io/gh/kitloong/laravel-migrations-generator/branch/6.x/graph/badge.svg?token=U6ZRDPY6QZ)](https://codecov.io/gh/kitloong/laravel-migrations-generator)
54
![Tests CI](https://github.com/kitloong/laravel-migrations-generator/actions/workflows/tests.yml/badge.svg?branch=6.x)
5+
[![codecov](https://codecov.io/gh/kitloong/laravel-migrations-generator/branch/6.x/graph/badge.svg?token=U6ZRDPY6QZ)](https://codecov.io/gh/kitloong/laravel-migrations-generator)
66
[![Latest Stable Version](https://poser.pugx.org/kitloong/laravel-migrations-generator/v/stable.png)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
77
[![Total Downloads](http://poser.pugx.org/kitloong/laravel-migrations-generator/downloads)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
88
[![License](https://poser.pugx.org/kitloong/laravel-migrations-generator/license.png)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
@@ -23,16 +23,16 @@ Laravel Migrations Generator supports all five Laravel first-party support datab
2323

2424
## Version Compatibility
2525

26-
|Laravel|Version|
27-
|---|---|
28-
|9.x|6.x|
29-
|8.x|6.x|
30-
|7.x|6.x|
31-
|6.x|6.x|
32-
|5.8.x|6.x|
33-
|5.7.x|6.x|
34-
|5.6.x|6.x|
35-
|5.5 and below|https://github.com/Xethron/migrations-generator|
26+
| Laravel | Version |
27+
|---------------|-------------------------------------------------|
28+
| 9.x | 6.x |
29+
| 8.x | 6.x |
30+
| 7.x | 6.x |
31+
| 6.x | 6.x |
32+
| 5.8.x | 6.x |
33+
| 5.7.x | 6.x |
34+
| 5.6.x | 6.x |
35+
| 5.5 and below | https://github.com/Xethron/migrations-generator |
3636

3737
## Install
3838

@@ -48,6 +48,9 @@ Laravel will automatically register service provider for you.
4848

4949
### Lumen Setup
5050

51+
<details>
52+
<summary>Expand</summary>
53+
5154
Auto-discovery is not available in Lumen, you need some modification on `bootstrap/app.php`.
5255

5356
#### Enable Facade
@@ -65,6 +68,7 @@ Add following line into the `Register Service Providers` section.
6568
```php
6669
$app->register(\KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
6770
```
71+
</details>
6872

6973
## Usage
7074

@@ -120,13 +124,15 @@ Run `php artisan help migrate:generate` for a list of options.
120124
| -p, --path[=PATH] | Where should the file be created? |
121125
| -tp, --template-path[=TEMPLATE-PATH] | The location of the template for this generator |
122126
| --date[=DATE] | Migrations will be created with specified date. Views and Foreign keys will be created with + 1 second. Date should be in format supported by `Carbon::parse` |
123-
| --table-filename[=TABLE-FILENAME] | Define table migration filename, default pattern: `[datetime_prefix]\_create_[table]_table.php` |
124-
| --view-filename[=VIEW-FILENAME] | Define view migration filename, default pattern: `[datetime_prefix]\_create_[table]_view.php` |
125-
| --fk-filename[=FK-FILENAME] | Define foreign key migration filename, default pattern: `[datetime_prefix]\_add_foreign_keys_to_[table]_table.php` |
127+
| --table-filename[=TABLE-FILENAME] | Define table migration filename, default pattern: `[datetime]\_create_[name]_table.php` |
128+
| --view-filename[=VIEW-FILENAME] | Define view migration filename, default pattern: `[datetime]\_create_[name]_view.php` |
129+
| --proc-filename[=PROC-FILENAME] | Define stored procedure filename, default pattern: `[datetime]\_create_[name]_proc.php` |
130+
| --fk-filename[=FK-FILENAME] | Define foreign key migration filename, default pattern: `[datetime]\_add_foreign_keys_to_[name]_table.php` |
126131
| --default-index-names | Don\'t use DB index names for migrations |
127132
| --default-fk-names | Don\'t use DB foreign key names for migrations |
128133
| --use-db-collation | Generate migrations with existing DB collation |
129134
| --skip-views | Don\'t generate views |
135+
| --skip-proc | Don\'t generate stored procedures |
130136
| --squash | Generate all migrations into a single file |
131137

132138
## SQLite Alter Foreign Key

composer.json

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"friendsofphp/php-cs-fixer": "^2.19.0|^3.1",
2424
"nunomaduro/larastan": "^0.4|^0.5|^0.6|^0.7|^1.0|^2.0",
2525
"phpmd/phpmd": "^2.10",
26-
"barryvdh/laravel-ide-helper": "^2.7"
26+
"barryvdh/laravel-ide-helper": "^2.7",
27+
"slevomat/coding-standard": "^6.0|^7.0|^8.5"
2728
},
2829
"autoload": {
2930
"psr-4": {
@@ -50,21 +51,13 @@
5051
],
5152
"phpcs": ["phpcs"],
5253
"phpmd": ["phpmd \"src,tests\" xml .phpmd.xml"],
53-
"phpstan": ["phpstan analyse"],
54-
"check-migrations": [
55-
"rm -rf migrations/mysql8/* migrations/mysql57/* migrations/pgsql/* migrations/sqlsrv/* migrations/mariadb/* migrations/sqlite/*",
56-
"phpunit --filter testRun tests/Feature/MySQL57/CommandTest.php && cp storage/migrations/* migrations/mysql57/ && cp storage/sql/* migrations/mysql57/",
57-
"phpunit --filter testCollation tests/Feature/MySQL57/CommandTest.php && cp storage/migrations/* migrations/mysql57/",
58-
"phpunit --filter testRun tests/Feature/MySQL8/CommandTest.php && cp storage/migrations/* migrations/mysql8/ && cp storage/sql/* migrations/mysql8/",
59-
"phpunit --filter testCollation tests/Feature/MySQL8/CommandTest.php && cp storage/migrations/* migrations/mysql8/",
60-
"phpunit --filter testRun tests/Feature/PgSQL/CommandTest.php && cp storage/migrations/* migrations/pgsql/ && cp storage/sql/* migrations/pgsql/",
61-
"phpunit --filter testCollation tests/Feature/PgSQL/CommandTest.php && cp storage/migrations/* migrations/pgsql/",
62-
"phpunit --filter testRun tests/Feature/SQLSrv/CommandTest.php && cp storage/migrations/* migrations/sqlsrv/ && cp storage/sql/* migrations/sqlsrv/",
63-
"phpunit --filter testCollation tests/Feature/SQLSrv/CommandTest.php && cp storage/migrations/* migrations/sqlsrv/",
64-
"phpunit --filter testRun tests/Feature/MariaDB/CommandTest.php && cp storage/migrations/* migrations/mariadb/ && cp storage/sql/* migrations/mariadb/",
65-
"phpunit --filter testCollation tests/Feature/MariaDB/CommandTest.php && cp storage/migrations/* migrations/mariadb/",
66-
"phpunit --filter testRun tests/Feature/SQLite/CommandTest.php && cp storage/migrations/* migrations/sqlite/ && cp storage/sql/* migrations/sqlite/",
67-
"phpunit --filter testCollation tests/Feature/SQLite/CommandTest.php && cp storage/migrations/* migrations/sqlite/"
54+
"phpstan": [
55+
"phpstan analyse"
6856
]
69-
}
57+
},
58+
"config": {
59+
"allow-plugins": {
60+
"dealerdirect/phpcodesniffer-composer-installer": true
61+
}
62+
}
7063
}

config/config.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
return [
44
// Where the templates for the generators are stored.
5-
'migration_template_path' => __DIR__ . '/../resources/stub/migration.stub',
5+
'migration_template_path' => __DIR__ . '/../resources/stub/migration.stub',
66

77
// Where the generated files will be saved.
8-
'migration_target_path' => base_path('database/migrations'),
8+
'migration_target_path' => base_path('database/migrations'),
99

1010
// Migration filename pattern.
11-
'filename_pattern' => [
12-
'table' => '[datetime_prefix]_create_[table]_table.php',
13-
'view' => '[datetime_prefix]_create_[table]_view.php',
14-
'foreign_key' => '[datetime_prefix]_add_foreign_keys_to_[table]_table.php',
11+
'filename_pattern' => [
12+
'table' => '[datetime]_create_[name]_table.php',
13+
'view' => '[datetime]_create_[name]_view.php',
14+
'procedure' => '[datetime]_create_[name]_proc.php',
15+
'foreign_key' => '[datetime]_add_foreign_keys_to_[name]_table.php',
1516
],
1617
];

phpcs.xml

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,102 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="laravel-migrations-generator" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3-
<description>Custom code standard for Laravel Migrations Generator</description>
3+
<description>Custom code standard for Laravel Migrations Generator</description>
44

5-
<rule ref="PSR12">
6-
<exclude name="Generic.Files.LineLength"/>
7-
</rule>
5+
<file>src</file>
6+
<file>tests</file>
87

9-
<file>src</file>
10-
<file>tests</file>
8+
<exclude-pattern>tests/resources/database/migrations/*.php</exclude-pattern>
119

12-
<exclude-pattern>tests/resources/database/migrations/*.php</exclude-pattern>
10+
<rule ref="PSR12">
11+
<exclude name="Generic.Files.LineLength"/>
12+
</rule>
13+
14+
<!-- Align corresponding assignment statement tokens -->
15+
<rule ref="Generic.Formatting.MultipleStatementAlignment">
16+
<properties>
17+
<property name="error" value="true"/>
18+
</properties>
19+
</rule>
20+
21+
<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>
22+
23+
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
24+
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
25+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
26+
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing"/>
27+
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing"/>
28+
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration"/>
29+
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/>
30+
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature"/>
31+
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
32+
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing"/>
33+
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
34+
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
35+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
36+
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
37+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
38+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
39+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
40+
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
41+
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
42+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition"/>
43+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
44+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
45+
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
46+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
47+
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
48+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
49+
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
50+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
51+
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
52+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
53+
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
54+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration"/>
55+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
56+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
57+
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
58+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
59+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
60+
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
61+
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
62+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
63+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
64+
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing"/>
65+
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
66+
<rule ref="SlevomatCodingStandard.Operators.RequireOnlyStandaloneIncrementAndDecrementOperators"/>
67+
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing"/>
68+
<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall"/>
69+
<rule ref="SlevomatCodingStandard.PHP.DisallowReference"/>
70+
<rule ref="SlevomatCodingStandard.PHP.ForbiddenClasses"/>
71+
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
72+
<rule ref="SlevomatCodingStandard.PHP.RequireNowdoc"/>
73+
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
74+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
75+
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
76+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
77+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
78+
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
79+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
80+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
81+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
82+
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"/>
83+
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
84+
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>
85+
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
86+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable"/>
87+
<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces">
88+
<properties>
89+
<property name="ignoreSpacesBeforeAssignment" value="true"/>
90+
<property name="ignoreSpacesInComment" value="true"/>
91+
<property name="ignoreSpacesInParameters" value="true"/>
92+
</properties>
93+
</rule>
94+
95+
<!-- <rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment"/>-->
96+
<!-- <rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>-->
97+
<!-- <rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>-->
98+
<!-- <rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>-->
99+
<!-- <rule ref="SlevomatCodingStandard.Complexity.Cognitive"/>-->
100+
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty"/>-->
101+
<!-- <rule ref="SlevomatCodingStandard.Functions.StrictCall"/>-->
13102
</ruleset>

src/DBAL/DBALSchema.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace KitLoong\MigrationsGenerator\DBAL;
44

55
use Doctrine\DBAL\Schema\AbstractSchemaManager;
6+
use Doctrine\DBAL\Schema\Table;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\Facades\DB;
89
use KitLoong\MigrationsGenerator\Schema\Schema;
@@ -36,10 +37,29 @@ public function getTableNames(): Collection
3637
if ($this->isIdentifierQuoted($table)) {
3738
return $this->trimQuotes($table);
3839
}
40+
3941
return $table;
4042
});
4143
}
4244

45+
/**
46+
* Introspects the table with the given name.
47+
* `listTableDetails` is deprecated since `doctrine/dbal` v3.5 and will be removed from v4.
48+
* This method will try to call `introspectTable` and fallback to `listTableDetails`.
49+
*
50+
* @param string $name
51+
* @return \Doctrine\DBAL\Schema\Table
52+
* @throws \Doctrine\DBAL\Exception
53+
*/
54+
protected function introspectTable(string $name): Table
55+
{
56+
if (method_exists($this->dbalSchema, 'introspectTable')) {
57+
return $this->dbalSchema->introspectTable($name);
58+
}
59+
60+
return $this->dbalSchema->listTableDetails($name);
61+
}
62+
4363
/**
4464
* Make a schema manager.
4565
*
@@ -49,6 +69,7 @@ public function getTableNames(): Collection
4969
private function makeSchemaManager(): AbstractSchemaManager
5070
{
5171
$doctrineConnection = DB::getDoctrineConnection();
72+
5273
if (method_exists($doctrineConnection, 'createSchemaManager')) {
5374
return $doctrineConnection->createSchemaManager();
5475
}

0 commit comments

Comments
 (0)