Skip to content

Commit

Permalink
Merge pull request #129 from kitloong/feature/procedure
Browse files Browse the repository at this point in the history
Generate store procedures
  • Loading branch information
kitloong authored Nov 1, 2022
2 parents fc37c5e + 1bf3fb3 commit 124a5be
Show file tree
Hide file tree
Showing 124 changed files with 2,215 additions and 1,020 deletions.
24 changes: 13 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.env.* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpmd.xml export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/phpunit.xml export-ignore
/testbench.yaml export-ignore
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.env.* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpmd.xml export-ignore
/check_migrations.sh export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/phpunit.xml export-ignore
/phpunit8.xml export-ignore
/testbench.yaml export-ignore
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ jobs:
laravel: 8.*
dbal: 3.*
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2
- php: 8.2
laravel: 9.*
dbal: 3.*
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2
- php: 8.2
laravel: 8.*
dbal: 3.*
sqlsrv_extension: pdo_sqlsrv-5.10.0beta2

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

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.phpstorm.meta.php
.phpunit.result.cache
_ide_helper.php
check_migrations.sh
docker-compose.yml
composer.lock
coverage.xml
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Laravel Migrations Generator

![Style check CI](https://github.com/kitloong/laravel-migrations-generator/actions/workflows/check.yml/badge.svg?branch=6.x)
[![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)
![Tests CI](https://github.com/kitloong/laravel-migrations-generator/actions/workflows/tests.yml/badge.svg?branch=6.x)
[![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)
[![Latest Stable Version](https://poser.pugx.org/kitloong/laravel-migrations-generator/v/stable.png)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
[![Total Downloads](http://poser.pugx.org/kitloong/laravel-migrations-generator/downloads)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
[![License](https://poser.pugx.org/kitloong/laravel-migrations-generator/license.png)](https://packagist.org/packages/kitloong/laravel-migrations-generator)
Expand All @@ -23,16 +23,16 @@ Laravel Migrations Generator supports all five Laravel first-party support datab

## Version Compatibility

|Laravel|Version|
|---|---|
|9.x|6.x|
|8.x|6.x|
|7.x|6.x|
|6.x|6.x|
|5.8.x|6.x|
|5.7.x|6.x|
|5.6.x|6.x|
|5.5 and below|https://github.com/Xethron/migrations-generator|
| Laravel | Version |
|---------------|-------------------------------------------------|
| 9.x | 6.x |
| 8.x | 6.x |
| 7.x | 6.x |
| 6.x | 6.x |
| 5.8.x | 6.x |
| 5.7.x | 6.x |
| 5.6.x | 6.x |
| 5.5 and below | https://github.com/Xethron/migrations-generator |

## Install

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

### Lumen Setup

<details>
<summary>Expand</summary>

Auto-discovery is not available in Lumen, you need some modification on `bootstrap/app.php`.

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

## Usage

Expand Down Expand Up @@ -120,13 +124,15 @@ Run `php artisan help migrate:generate` for a list of options.
| -p, --path[=PATH] | Where should the file be created? |
| -tp, --template-path[=TEMPLATE-PATH] | The location of the template for this generator |
| --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` |
| --table-filename[=TABLE-FILENAME] | Define table migration filename, default pattern: `[datetime_prefix]\_create_[table]_table.php` |
| --view-filename[=VIEW-FILENAME] | Define view migration filename, default pattern: `[datetime_prefix]\_create_[table]_view.php` |
| --fk-filename[=FK-FILENAME] | Define foreign key migration filename, default pattern: `[datetime_prefix]\_add_foreign_keys_to_[table]_table.php` |
| --table-filename[=TABLE-FILENAME] | Define table migration filename, default pattern: `[datetime]\_create_[name]_table.php` |
| --view-filename[=VIEW-FILENAME] | Define view migration filename, default pattern: `[datetime]\_create_[name]_view.php` |
| --proc-filename[=PROC-FILENAME] | Define stored procedure filename, default pattern: `[datetime]\_create_[name]_proc.php` |
| --fk-filename[=FK-FILENAME] | Define foreign key migration filename, default pattern: `[datetime]\_add_foreign_keys_to_[name]_table.php` |
| --default-index-names | Don\'t use DB index names for migrations |
| --default-fk-names | Don\'t use DB foreign key names for migrations |
| --use-db-collation | Generate migrations with existing DB collation |
| --skip-views | Don\'t generate views |
| --skip-proc | Don\'t generate stored procedures |
| --squash | Generate all migrations into a single file |

## SQLite Alter Foreign Key
Expand Down
27 changes: 10 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"friendsofphp/php-cs-fixer": "^2.19.0|^3.1",
"nunomaduro/larastan": "^0.4|^0.5|^0.6|^0.7|^1.0|^2.0",
"phpmd/phpmd": "^2.10",
"barryvdh/laravel-ide-helper": "^2.7"
"barryvdh/laravel-ide-helper": "^2.7",
"slevomat/coding-standard": "^6.0|^7.0|^8.5"
},
"autoload": {
"psr-4": {
Expand All @@ -50,21 +51,13 @@
],
"phpcs": ["phpcs"],
"phpmd": ["phpmd \"src,tests\" xml .phpmd.xml"],
"phpstan": ["phpstan analyse"],
"check-migrations": [
"rm -rf migrations/mysql8/* migrations/mysql57/* migrations/pgsql/* migrations/sqlsrv/* migrations/mariadb/* migrations/sqlite/*",
"phpunit --filter testRun tests/Feature/MySQL57/CommandTest.php && cp storage/migrations/* migrations/mysql57/ && cp storage/sql/* migrations/mysql57/",
"phpunit --filter testCollation tests/Feature/MySQL57/CommandTest.php && cp storage/migrations/* migrations/mysql57/",
"phpunit --filter testRun tests/Feature/MySQL8/CommandTest.php && cp storage/migrations/* migrations/mysql8/ && cp storage/sql/* migrations/mysql8/",
"phpunit --filter testCollation tests/Feature/MySQL8/CommandTest.php && cp storage/migrations/* migrations/mysql8/",
"phpunit --filter testRun tests/Feature/PgSQL/CommandTest.php && cp storage/migrations/* migrations/pgsql/ && cp storage/sql/* migrations/pgsql/",
"phpunit --filter testCollation tests/Feature/PgSQL/CommandTest.php && cp storage/migrations/* migrations/pgsql/",
"phpunit --filter testRun tests/Feature/SQLSrv/CommandTest.php && cp storage/migrations/* migrations/sqlsrv/ && cp storage/sql/* migrations/sqlsrv/",
"phpunit --filter testCollation tests/Feature/SQLSrv/CommandTest.php && cp storage/migrations/* migrations/sqlsrv/",
"phpunit --filter testRun tests/Feature/MariaDB/CommandTest.php && cp storage/migrations/* migrations/mariadb/ && cp storage/sql/* migrations/mariadb/",
"phpunit --filter testCollation tests/Feature/MariaDB/CommandTest.php && cp storage/migrations/* migrations/mariadb/",
"phpunit --filter testRun tests/Feature/SQLite/CommandTest.php && cp storage/migrations/* migrations/sqlite/ && cp storage/sql/* migrations/sqlite/",
"phpunit --filter testCollation tests/Feature/SQLite/CommandTest.php && cp storage/migrations/* migrations/sqlite/"
"phpstan": [
"phpstan analyse"
]
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
13 changes: 7 additions & 6 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

return [
// Where the templates for the generators are stored.
'migration_template_path' => __DIR__ . '/../resources/stub/migration.stub',
'migration_template_path' => __DIR__ . '/../resources/stub/migration.stub',

// Where the generated files will be saved.
'migration_target_path' => base_path('database/migrations'),
'migration_target_path' => base_path('database/migrations'),

// Migration filename pattern.
'filename_pattern' => [
'table' => '[datetime_prefix]_create_[table]_table.php',
'view' => '[datetime_prefix]_create_[table]_view.php',
'foreign_key' => '[datetime_prefix]_add_foreign_keys_to_[table]_table.php',
'filename_pattern' => [
'table' => '[datetime]_create_[name]_table.php',
'view' => '[datetime]_create_[name]_view.php',
'procedure' => '[datetime]_create_[name]_proc.php',
'foreign_key' => '[datetime]_add_foreign_keys_to_[name]_table.php',
],
];
103 changes: 96 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,102 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="laravel-migrations-generator" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Custom code standard for Laravel Migrations Generator</description>
<description>Custom code standard for Laravel Migrations Generator</description>

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>
<file>src</file>
<file>tests</file>

<file>src</file>
<file>tests</file>
<exclude-pattern>tests/resources/database/migrations/*.php</exclude-pattern>

<exclude-pattern>tests/resources/database/migrations/*.php</exclude-pattern>
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>

<!-- Align corresponding assignment statement tokens -->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="error" value="true"/>
</properties>
</rule>

<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>

<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/>
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature"/>
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing"/>
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition"/>
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing"/>
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
<rule ref="SlevomatCodingStandard.Operators.RequireOnlyStandaloneIncrementAndDecrementOperators"/>
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing"/>
<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall"/>
<rule ref="SlevomatCodingStandard.PHP.DisallowReference"/>
<rule ref="SlevomatCodingStandard.PHP.ForbiddenClasses"/>
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
<rule ref="SlevomatCodingStandard.PHP.RequireNowdoc"/>
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"/>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable"/>
<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces">
<properties>
<property name="ignoreSpacesBeforeAssignment" value="true"/>
<property name="ignoreSpacesInComment" value="true"/>
<property name="ignoreSpacesInParameters" value="true"/>
</properties>
</rule>

<!-- <rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment"/>-->
<!-- <rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>-->
<!-- <rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>-->
<!-- <rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>-->
<!-- <rule ref="SlevomatCodingStandard.Complexity.Cognitive"/>-->
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty"/>-->
<!-- <rule ref="SlevomatCodingStandard.Functions.StrictCall"/>-->
</ruleset>
21 changes: 21 additions & 0 deletions src/DBAL/DBALSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace KitLoong\MigrationsGenerator\DBAL;

use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use KitLoong\MigrationsGenerator\Schema\Schema;
Expand Down Expand Up @@ -36,10 +37,29 @@ public function getTableNames(): Collection
if ($this->isIdentifierQuoted($table)) {
return $this->trimQuotes($table);
}

return $table;
});
}

/**
* Introspects the table with the given name.
* `listTableDetails` is deprecated since `doctrine/dbal` v3.5 and will be removed from v4.
* This method will try to call `introspectTable` and fallback to `listTableDetails`.
*
* @param string $name
* @return \Doctrine\DBAL\Schema\Table
* @throws \Doctrine\DBAL\Exception
*/
protected function introspectTable(string $name): Table
{
if (method_exists($this->dbalSchema, 'introspectTable')) {
return $this->dbalSchema->introspectTable($name);
}

return $this->dbalSchema->listTableDetails($name);
}

/**
* Make a schema manager.
*
Expand All @@ -49,6 +69,7 @@ public function getTableNames(): Collection
private function makeSchemaManager(): AbstractSchemaManager
{
$doctrineConnection = DB::getDoctrineConnection();

if (method_exists($doctrineConnection, 'createSchemaManager')) {
return $doctrineConnection->createSchemaManager();
}
Expand Down
Loading

0 comments on commit 124a5be

Please sign in to comment.