├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ ├── dacapo-testing.yml
│ ├── phpstan.yml
│ └── pint.yml
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── composer.json
├── phpstan.neon
├── phpunit.xml
├── pint.json
├── renovate.json
├── src
├── Dacapo
│ ├── Application
│ │ └── UseCase
│ │ │ ├── DacapoCommandUseCase.php
│ │ │ ├── Input
│ │ │ └── DacapoCommandUseCaseInput.php
│ │ │ └── Output
│ │ │ └── DacapoCommandUseCaseOutput.php
│ ├── Console
│ │ ├── DacapoClearCommand.php
│ │ ├── DacapoCommand.php
│ │ ├── DacapoConfigPublishCommand.php
│ │ ├── DacapoInitCommand.php
│ │ ├── DacapoInitCommand
│ │ │ └── laravel9.yml
│ │ ├── DacapoStubPublishCommand.php
│ │ └── DacapoUninstallCommand.php
│ ├── Domain
│ │ ├── MigrationFile
│ │ │ ├── Driver
│ │ │ │ └── DatabaseDriver.php
│ │ │ ├── MigrationFile.php
│ │ │ └── Stub
│ │ │ │ ├── MigrationCreateStub.php
│ │ │ │ └── MigrationUpdateStub.php
│ │ ├── Schema
│ │ │ ├── ForeignKey
│ │ │ │ ├── ForeignKey.php
│ │ │ │ ├── ForeignKeyList.php
│ │ │ │ ├── Reference.php
│ │ │ │ └── ReferenceAction.php
│ │ │ ├── IndexModifier
│ │ │ │ ├── IndexModifier.php
│ │ │ │ ├── IndexModifierList.php
│ │ │ │ └── IndexModifierType
│ │ │ │ │ ├── FullTextType.php
│ │ │ │ │ ├── IndexModifierType.php
│ │ │ │ │ ├── IndexModifierTypeFactory.php
│ │ │ │ │ ├── IndexType.php
│ │ │ │ │ ├── PrimaryType.php
│ │ │ │ │ ├── SpatialIndexType.php
│ │ │ │ │ └── UniqueType.php
│ │ │ ├── Schema.php
│ │ │ ├── SchemaList.php
│ │ │ └── Table
│ │ │ │ ├── Charset.php
│ │ │ │ ├── Collation.php
│ │ │ │ ├── Column
│ │ │ │ ├── Column.php
│ │ │ │ ├── ColumnList.php
│ │ │ │ ├── ColumnModifier
│ │ │ │ │ ├── AlwaysModifier.php
│ │ │ │ │ ├── AutoIncrementModifier.php
│ │ │ │ │ ├── CharsetModifier.php
│ │ │ │ │ ├── CollationModifier.php
│ │ │ │ │ ├── ColumnModifier.php
│ │ │ │ │ ├── ColumnModifierArgs
│ │ │ │ │ │ ├── BooleanColumnModifierArgs.php
│ │ │ │ │ │ ├── ColumnModifierArgs.php
│ │ │ │ │ │ ├── IntColumnModifierArgs.php
│ │ │ │ │ │ ├── MixedColumnModifierArgs.php
│ │ │ │ │ │ └── StringColumnModifierArgs.php
│ │ │ │ │ ├── ColumnModifierFactory.php
│ │ │ │ │ ├── ColumnModifierList.php
│ │ │ │ │ ├── CommentModifier.php
│ │ │ │ │ ├── DbFacadeUsing.php
│ │ │ │ │ ├── DefaultModifier.php
│ │ │ │ │ ├── DefaultRawModifier.php
│ │ │ │ │ ├── FromModifier.php
│ │ │ │ │ ├── GeneratedAsModifier.php
│ │ │ │ │ ├── IndexModifier.php
│ │ │ │ │ ├── NullableModifier.php
│ │ │ │ │ ├── StoredAsModifier.php
│ │ │ │ │ ├── UniqueModifier.php
│ │ │ │ │ ├── UnsignedModifier.php
│ │ │ │ │ ├── UseCurrentModifier.php
│ │ │ │ │ ├── UseCurrentOnUpdateModifier.php
│ │ │ │ │ └── VirtualAsModifier.php
│ │ │ │ ├── ColumnName.php
│ │ │ │ ├── ColumnType
│ │ │ │ │ ├── AliasColumnType.php
│ │ │ │ │ ├── ArrayArgsColumnType.php
│ │ │ │ │ ├── BigIncrementsType.php
│ │ │ │ │ ├── BigIntegerType.php
│ │ │ │ │ ├── BinaryType.php
│ │ │ │ │ ├── BooleanArgsColumnType.php
│ │ │ │ │ ├── BooleanType.php
│ │ │ │ │ ├── CharType.php
│ │ │ │ │ ├── ColumnType.php
│ │ │ │ │ ├── ColumnTypeFactory.php
│ │ │ │ │ ├── DateTimeType.php
│ │ │ │ │ ├── DateTimeTzType.php
│ │ │ │ │ ├── DateType.php
│ │ │ │ │ ├── DecimalType.php
│ │ │ │ │ ├── DoubleType.php
│ │ │ │ │ ├── EnumType.php
│ │ │ │ │ ├── FloatType.php
│ │ │ │ │ ├── ForeignIdType.php
│ │ │ │ │ ├── GeometryCollectionType.php
│ │ │ │ │ ├── GeometryType.php
│ │ │ │ │ ├── IdType.php
│ │ │ │ │ ├── IncrementsType.php
│ │ │ │ │ ├── IntegerType.php
│ │ │ │ │ ├── IpAddressType.php
│ │ │ │ │ ├── JsonType.php
│ │ │ │ │ ├── JsonbType.php
│ │ │ │ │ ├── LineStringType.php
│ │ │ │ │ ├── LongTextType.php
│ │ │ │ │ ├── MacAddressType.php
│ │ │ │ │ ├── MediumIncrementsType.php
│ │ │ │ │ ├── MediumIntegerType.php
│ │ │ │ │ ├── MediumTextType.php
│ │ │ │ │ ├── MorphsType.php
│ │ │ │ │ ├── MultiLineStringType.php
│ │ │ │ │ ├── MultiPointType.php
│ │ │ │ │ ├── MultiPolygonType.php
│ │ │ │ │ ├── NullableMorphsType.php
│ │ │ │ │ ├── NullableTimestampsType.php
│ │ │ │ │ ├── NullableUuidMorphsType.php
│ │ │ │ │ ├── NumericArgsColumnType.php
│ │ │ │ │ ├── PointType.php
│ │ │ │ │ ├── PolygonType.php
│ │ │ │ │ ├── RememberTokenType.php
│ │ │ │ │ ├── SetType.php
│ │ │ │ │ ├── SmallIncrementsType.php
│ │ │ │ │ ├── SmallIntegerType.php
│ │ │ │ │ ├── SoftDeletesType.php
│ │ │ │ │ ├── SoftDeletesTzType.php
│ │ │ │ │ ├── StringArgsColumnType.php
│ │ │ │ │ ├── StringType.php
│ │ │ │ │ ├── TextType.php
│ │ │ │ │ ├── TimeType.php
│ │ │ │ │ ├── TimeTzType.php
│ │ │ │ │ ├── TimestampType.php
│ │ │ │ │ ├── TimestampTzType.php
│ │ │ │ │ ├── TimestampsType.php
│ │ │ │ │ ├── TimestampsTzType.php
│ │ │ │ │ ├── TinyIncrementsType.php
│ │ │ │ │ ├── TinyIntegerType.php
│ │ │ │ │ ├── UnsignedBigIntegerType.php
│ │ │ │ │ ├── UnsignedDecimalType.php
│ │ │ │ │ ├── UnsignedIntegerType.php
│ │ │ │ │ ├── UnsignedMediumIntegerType.php
│ │ │ │ │ ├── UnsignedSmallIntegerType.php
│ │ │ │ │ ├── UnsignedTinyIntegerType.php
│ │ │ │ │ ├── UuidMorphsType.php
│ │ │ │ │ ├── UuidType.php
│ │ │ │ │ └── YearType.php
│ │ │ │ └── ColumnTypeArgs.php
│ │ │ │ ├── Connection.php
│ │ │ │ ├── Engine.php
│ │ │ │ ├── Table.php
│ │ │ │ ├── TableComment.php
│ │ │ │ ├── TableName.php
│ │ │ │ └── Temporary.php
│ │ └── Shared
│ │ │ └── Exception
│ │ │ └── Schema
│ │ │ ├── Column
│ │ │ ├── ColumnModifier
│ │ │ │ └── InvalidArgumentException.php
│ │ │ ├── ColumnType
│ │ │ │ └── InvalidArgumentException.php
│ │ │ └── InvalidArgumentException.php
│ │ │ ├── DuplicatedTableNameException.php
│ │ │ ├── ForeignKey
│ │ │ └── InvalidArgumentException.php
│ │ │ └── IndexModifier
│ │ │ ├── IndexModifierType
│ │ │ └── InvalidArgumentException.php
│ │ │ └── InvalidArgumentException.php
│ ├── Exception
│ │ └── Console
│ │ │ ├── DuplicatedTableNameException.php
│ │ │ └── SchemaFileEmptyException.php
│ ├── Infra
│ │ └── Adapter
│ │ │ ├── Driver
│ │ │ ├── MysqlDatabaseDriver.php
│ │ │ ├── PostgresqlDatabaseDriver.php
│ │ │ ├── SqliteDatabaseDriver.php
│ │ │ └── SqlsrvDatabaseDriver.php
│ │ │ ├── InMemoryDatabaseMigrationsStorage.php
│ │ │ ├── LaravelDatabaseMigrationsStorage.php
│ │ │ ├── LaravelDatabaseSchemasStorage.php
│ │ │ └── Stub
│ │ │ ├── LaravelMigrationCreateStub.php
│ │ │ ├── LaravelMigrationUpdateStub.php
│ │ │ ├── dacapo.migration.create.stub
│ │ │ └── dacapo.migration.update.stub
│ └── Storage
│ │ ├── DatabaseMigrationsStorage.php
│ │ └── DatabaseSchemasStorage.php
└── Providers
│ └── ConsoleServiceProvider.php
└── tools
├── phpstan
├── .gitignore
├── composer.json
└── composer.lock
└── pint
├── .gitignore
├── composer.json
└── composer.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 4
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
14 | [*.yml]
15 | indent_size = 2
16 |
17 | [Makefile]
18 | indent_style = tab
19 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | /tests export-ignore
2 |
--------------------------------------------------------------------------------
/.github/workflows/dacapo-testing.yml:
--------------------------------------------------------------------------------
1 | name: Dacapo Testing
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | dacapo-testing:
7 | name: Laravel Dacapo (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
8 | runs-on: ${{ matrix.operating-system }}
9 | strategy:
10 | fail-fast: false
11 | matrix:
12 | operating-system: [ubuntu-latest]
13 | php-versions: ['8.0', '8.1', '8.2']
14 |
15 | steps:
16 | - uses: actions/checkout@v3
17 |
18 | - name: Setup PHP
19 | uses: shivammathur/setup-php@v2
20 | with:
21 | php-version: ${{ matrix.php-versions }}
22 |
23 | - name: Version
24 | run: |
25 | cat /etc/os-release
26 | php -v
27 | composer --version
28 |
29 | - name: Install Dependencies
30 | run: |
31 | composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist
32 |
33 | - name: Execute tests via PHPUnit
34 | run: |
35 | composer test
36 |
--------------------------------------------------------------------------------
/.github/workflows/phpstan.yml:
--------------------------------------------------------------------------------
1 | name: PHPStan
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | phpstan:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v3
10 |
11 | - name: Install Dependencies
12 | run: |
13 | composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist --working-dir=tools/phpstan
14 | composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist
15 |
16 | - name: PHPStan Version
17 | run: ./tools/phpstan/vendor/bin/phpstan --version
18 |
19 | - name: PHPStan Analyse
20 | run: ./tools/phpstan/vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=1G
21 |
--------------------------------------------------------------------------------
/.github/workflows/pint.yml:
--------------------------------------------------------------------------------
1 | name: Laravel Pint
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | pint:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v3
10 |
11 | - name: Install Dependencies
12 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist --working-dir=tools/pint
13 |
14 | - name: Laravel Pint Dry Run
15 | run: ./tools/pint/vendor/bin/pint -v --test
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | /composer.lock
3 | /.phpunit.result.cache
4 | /.php-cs-fixer.cache
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 ucan-lab
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | composer-install-tools:
2 | composer install --working-dir=tools/pint
3 | composer install --working-dir=tools/phpstan
4 | pint:
5 | ./tools/pint/vendor/bin/pint -v
6 | stan:
7 | ./tools/phpstan/vendor/bin/phpstan analyse -c phpstan.neon
8 | test:
9 | ./vendor/bin/phpunit
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel-Dacapo
2 |
3 | [](https://travis-ci.org/ucan-lab/laravel-dacapo)
4 | [](https://packagist.org/packages/ucan-lab/laravel-dacapo)
5 | [](https://packagist.org/packages/ucan-lab/laravel-dacapo)
6 | [](https://packagist.org/packages/ucan-lab/laravel-dacapo)
7 | [](https://packagist.org/packages/ucan-lab/laravel-dacapo)
8 |
9 | ## Introduction
10 |
11 | Dacapo is a Laravel migration file creation support library.
12 | Define the table structure in the schema yml file, Always generate the latest and tidy migration file.
13 |
14 | This library is intended for use only in the coding phase.
15 | In the operation phase, uninstall and return to normal migration operation.
16 |
17 | ## Installation
18 |
19 | ```
20 | $ composer require --dev ucan-lab/laravel-dacapo
21 | ```
22 |
23 | ## Usage
24 |
25 | ### Generate default schema.yml
26 |
27 | ```
28 | $ php artisan dacapo:init
29 | ```
30 |
31 | `database/schemas/default.yml`
32 | By default, a schema file for Laravel8 is generated.
33 |
34 | ```yaml
35 | users:
36 | columns:
37 | id:
38 | name: string
39 | email:
40 | type: string
41 | unique:
42 | email_verified_at:
43 | type: timestamp
44 | nullable:
45 | password: string
46 | rememberToken:
47 | timestamps:
48 |
49 | password_resets:
50 | columns:
51 | email:
52 | type: string
53 | index:
54 | token: string
55 | created_at:
56 | type: timestamp
57 | nullable:
58 |
59 | failed_jobs:
60 | columns:
61 | id:
62 | uuid:
63 | type: string
64 | unique:
65 | connection: text
66 | queue: text
67 | payload: longText
68 | exception: longText
69 | failed_at:
70 | type: timestamp
71 | useCurrent:
72 | ```
73 |
74 | ### Generate migration files
75 |
76 | ```
77 | $ php artisan dacapo
78 | ```
79 |
80 | 3 files are generated and migrate fresh.
81 |
82 | - 1970_01_01_000001_create_failed_jobs_table.php
83 | - 1970_01_01_000001_create_password_resets_table.php
84 | - 1970_01_01_000001_create_users_table.php
85 |
86 | #### Dacapo Option
87 |
88 | ```
89 | # Execute migrate and seeding
90 | $ php artisan dacapo --seed
91 | ```
92 |
93 | ```
94 | # Do not execute migrate
95 | $ php artisan dacapo --no-migrate
96 | ```
97 |
98 | ### Schema file format
99 |
100 | - `{}` any value
101 | - `database/schemas/*.yml`
102 | - If it cannot be expressed in YAML, it can be used together with standard migration.
103 | - `php artisan make:migration`
104 |
105 | ```
106 | # COMMENT
107 | {TableName}:
108 | columns:
109 | {ColumnName}: {ColumnType}
110 | {ColumnName}:
111 | type: {ColumnType}
112 | {ColumnName}:
113 | unique: true
114 | nullable: true
115 | default: {DefaultValue}
116 | comment: {ColumnName}
117 | {ColumnModifier}: {ColumnModifierValue}
118 | indexes:
119 | - columns: {ColumnName}
120 | type: {IndexType}
121 | - columns: [{ColumnName}, {ColumnName}]
122 | type: {IndexType}
123 | - columns: {ColumnName}
124 | type: {IndexType}
125 | name: {IndexName}
126 | foreign_keys:
127 | - columns: {ColumnName}
128 | references: {ReferenceColumnName}
129 | table: {ReferenceTableName}
130 | - columns: {ColumnName}
131 | references: {ReferenceColumnName}
132 | table: {ReferenceTableName}
133 | onUpdateAction: {ConstraintProperty}
134 | onDeleteAction: {ConstraintProperty}
135 | - columns: [{ColumnName}, {ColumnName}]
136 | references: [{ReferenceColumnName}, {ReferenceColumnName}]
137 | table: {ReferenceTableName}
138 |
139 | {TableName}:
140 | columns:
141 | {ColumnName}: {ColumnType}
142 | ```
143 |
144 | ### Dacapo Clear Migrations
145 |
146 | ```
147 | $ php artisan dacapo:clear
148 | $ php artisan dacapo:clear --all
149 | ```
150 |
151 | - `--all` Delete including standard migration files.
152 |
153 | ### Dacapo Stub publish
154 |
155 | ```
156 | $ php artisan dacapo:stub:publish
157 | ```
158 |
159 | ### Dacapo Uninstall
160 |
161 | ```
162 | $ php artisan dacapo:uninstall
163 | $ composer remove --dev ucan-lab/laravel-dacapo
164 | ```
165 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ucan-lab/laravel-dacapo",
3 | "description": "Laravel migration support tools",
4 | "license": "MIT",
5 | "minimum-stability": "stable",
6 | "authors": [
7 | {
8 | "name": "ucan-lab",
9 | "email": "35098175+ucan-lab@users.noreply.github.com"
10 | }
11 | ],
12 | "keywords": [
13 | "laravel",
14 | "dacapo",
15 | "migration"
16 | ],
17 | "require": {
18 | "php": "^8.0.2",
19 | "laravel/framework": ">=9.21.0",
20 | "symfony/yaml": "^6.0"
21 | },
22 | "require-dev": {
23 | "roave/security-advisories": "dev-latest",
24 | "phpunit/phpunit": "9.5.27",
25 | "orchestra/testbench": "7.17.0"
26 | },
27 | "autoload": {
28 | "psr-4": {
29 | "UcanLab\\LaravelDacapo\\": "src/"
30 | }
31 | },
32 | "autoload-dev": {
33 | "psr-4": {
34 | "UcanLab\\LaravelDacapo\\Test\\": "tests/"
35 | }
36 | },
37 | "extra": {
38 | "laravel": {
39 | "providers": [
40 | "UcanLab\\LaravelDacapo\\Providers\\ConsoleServiceProvider"
41 | ]
42 | }
43 | },
44 | "scripts": {
45 | "test": [
46 | "phpunit"
47 | ]
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | parameters:
2 | level: 8
3 | paths:
4 | - src
5 | - tests
6 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 | ./tests
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pint.json:
--------------------------------------------------------------------------------
1 | {
2 | "preset": "laravel",
3 | "exclude": [
4 | "tests/Console/DacapoCommandTest"
5 | ],
6 | "rules": {
7 | "concat_space": false,
8 | "date_time_immutable": true,
9 | "declare_parentheses": true,
10 | "declare_strict_types": true,
11 | "final_class": true,
12 | "global_namespace_import": {
13 | "import_classes": true,
14 | "import_constants": true,
15 | "import_functions": true
16 | },
17 | "mb_str_functions": true,
18 | "no_superfluous_phpdoc_tags": true,
19 | "not_operator_with_successor_space": true,
20 | "phpdoc_align": {
21 | "align": "left"
22 | },
23 | "phpdoc_separation": false,
24 | "php_unit_test_case_static_method_calls": {
25 | "call_type": "this"
26 | },
27 | "simplified_if_return": true,
28 | "simplified_null_return": true
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/src/Dacapo/Application/UseCase/DacapoCommandUseCase.php:
--------------------------------------------------------------------------------
1 | databaseSchemasStorage->getSchemaList();
30 |
31 | $generatedFileNameList = $this->generateCreateTableMigrationFile($schemaList);
32 | $generatedFileNameList = array_merge($generatedFileNameList, $this->generateCreateIndexMigrationFile($schemaList));
33 | $generatedFileNameList = array_merge($generatedFileNameList, $this->generateConstraintForeignKeyMigrationFile($schemaList));
34 |
35 | sort($generatedFileNameList);
36 |
37 | return new DacapoCommandUseCaseOutput($generatedFileNameList);
38 | }
39 |
40 | /**
41 | * @return array
42 | */
43 | private function generateCreateTableMigrationFile(SchemaList $schemaList): array
44 | {
45 | $fileNameList = [];
46 |
47 | /** @var Schema $schema */
48 | foreach ($schemaList as $schema) {
49 | $migrationFile = $schema->makeCreateTableMigrationFile($this->databaseBuilder, $this->migrationCreateStub);
50 | $this->databaseMigrationsStorage->save($migrationFile);
51 | $fileNameList[] = $migrationFile->getName();
52 | }
53 |
54 | return $fileNameList;
55 | }
56 |
57 | /**
58 | * @return array
59 | */
60 | private function generateCreateIndexMigrationFile(SchemaList $schemaList): array
61 | {
62 | $fileNameList = [];
63 |
64 | /** @var Schema $schema */
65 | foreach ($schemaList as $schema) {
66 | $migrationFile = $schema->makeCreateIndexMigrationFile($this->migrationUpdateStub);
67 | if ($migrationFile) {
68 | $this->databaseMigrationsStorage->save($migrationFile);
69 | $fileNameList[] = $migrationFile->getName();
70 | }
71 | }
72 |
73 | return $fileNameList;
74 | }
75 |
76 | /**
77 | * @return array
78 | */
79 | private function generateConstraintForeignKeyMigrationFile(SchemaList $schemaList): array
80 | {
81 | $fileNameList = [];
82 |
83 | /** @var Schema $schema */
84 | foreach ($schemaList as $schema) {
85 | $migrationFile = $schema->makeConstraintForeignKeyMigrationFile($this->migrationUpdateStub);
86 | if ($migrationFile) {
87 | $this->databaseMigrationsStorage->save($migrationFile);
88 | $fileNameList[] = $migrationFile->getName();
89 | }
90 | }
91 |
92 | return $fileNameList;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/Dacapo/Application/UseCase/Input/DacapoCommandUseCaseInput.php:
--------------------------------------------------------------------------------
1 | $schemaBodies
11 | */
12 | public function __construct(public array $schemaBodies)
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Dacapo/Application/UseCase/Output/DacapoCommandUseCaseOutput.php:
--------------------------------------------------------------------------------
1 | $generatedFileNameList
11 | */
12 | public function __construct(public array $generatedFileNameList)
13 | {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoClearCommand.php:
--------------------------------------------------------------------------------
1 | newLine();
38 | $this->components->info('Deleting migration files.');
39 |
40 | $migrationsPath = $this->laravel->databasePath('migrations');
41 | $files = array_map(fn ($f) => (string) $f->getRealPath(), $filesystem->files($migrationsPath));
42 |
43 | if ($this->option('all') === false) {
44 | $files = array_filter($files, fn ($f) => str_contains($f, '1970_01_01'));
45 | }
46 |
47 | foreach ($files as $file) {
48 | $filesystem->delete($file);
49 | $this->components->task(pathinfo($file, PATHINFO_BASENAME));
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoCommand.php:
--------------------------------------------------------------------------------
1 | call('dacapo:clear', ['--force' => true]);
41 |
42 | $this->newLine();
43 | $this->components->info('Generating migration files.');
44 |
45 | $output = $useCase->handle();
46 |
47 | foreach ($output->generatedFileNameList as $generatedFileName) {
48 | $this->components->task($generatedFileName);
49 | }
50 |
51 | if ($this->option('no-migrate')) {
52 | $this->line('No migrate.');
53 |
54 | return;
55 | }
56 |
57 | $this->call('migrate:fresh', ['--force' => true]);
58 |
59 | if ($this->option('refresh')) {
60 | $this->call('migrate:refresh', ['--force' => true]);
61 | }
62 |
63 | if ($this->option('seed')) {
64 | $this->call('db:seed', ['--force' => true]);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoConfigPublishCommand.php:
--------------------------------------------------------------------------------
1 | laravel->configPath();
34 |
35 | $files = [
36 | (string) realpath(__DIR__ . '/DacapoConfigPublishCommand/dacapo.php') => $configPath . '/dacapo.php',
37 | ];
38 |
39 | foreach ($files as $from => $to) {
40 | if (! file_exists($to) || $this->option('force')) {
41 | file_put_contents($to, file_get_contents($from));
42 | }
43 | }
44 |
45 | $this->components->info('Config published successfully.');
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoInitCommand.php:
--------------------------------------------------------------------------------
1 | laravel->databasePath('schemas'))) {
37 | $filesystem->makeDirectory($schemasPath);
38 | }
39 |
40 | $version = 'laravel9';
41 |
42 | $from = __DIR__ . '/DacapoInitCommand/' . $version . '.yml';
43 | $to = $this->laravel->databasePath('schemas/default.yml');
44 | file_put_contents($to, file_get_contents($from));
45 | $this->newLine();
46 | $this->components->info('Generated database/schemas/default.yml');
47 |
48 | $this->call('dacapo:clear', ['--all' => true]);
49 | $this->call('dacapo', ['--no-migrate' => $this->option('no-migrate')]);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoInitCommand/laravel9.yml:
--------------------------------------------------------------------------------
1 | users:
2 | columns:
3 | id:
4 | name: string
5 | email:
6 | type: string
7 | unique:
8 | email_verified_at:
9 | type: timestamp
10 | nullable:
11 | password: string
12 | rememberToken:
13 | timestamps:
14 |
15 | password_resets:
16 | columns:
17 | email:
18 | type: string
19 | index:
20 | token: string
21 | created_at:
22 | type: timestamp
23 | nullable:
24 |
25 | failed_jobs:
26 | columns:
27 | id:
28 | uuid:
29 | type: string
30 | unique:
31 | connection: text
32 | queue: text
33 | payload: longText
34 | exception: longText
35 | failed_at:
36 | type: timestamp
37 | useCurrent:
38 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoStubPublishCommand.php:
--------------------------------------------------------------------------------
1 | laravel->basePath('stubs'))) {
35 | $filesystem->makeDirectory($stubsPath);
36 | }
37 |
38 | $files = [
39 | (string) realpath(__DIR__ . '/../Dacapo/Infra/Adapter/Stub/dacapo.migration.create.stub') => $stubsPath . '/dacapo.migration.create.stub',
40 | (string) realpath(__DIR__ . '/../Dacapo/Infra/Adapter/Stub/dacapo.migration.update.stub') => $stubsPath . '/dacapo.migration.update.stub',
41 | ];
42 |
43 | foreach ($files as $from => $to) {
44 | if (! file_exists($to) || $this->option('force')) {
45 | file_put_contents($to, file_get_contents($from));
46 | }
47 | }
48 |
49 | $this->components->info('Stubs published successfully.');
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Dacapo/Console/DacapoUninstallCommand.php:
--------------------------------------------------------------------------------
1 | newLine();
35 | $this->components->info('Uninstalling dacapo');
36 | if (is_dir($schemasPath = $this->laravel->databasePath('schemas'))) {
37 | $filesystem->deleteDirectory($schemasPath);
38 | }
39 |
40 | $this->components->info('Deleted schemas directory.');
41 | $this->components->info('Please dacapo composer remove package.');
42 | $this->comment('composer remove --dev ucan-lab/laravel-dacapo');
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/MigrationFile/Driver/DatabaseDriver.php:
--------------------------------------------------------------------------------
1 | contents = str_replace($placeholder, $value, $this->contents);
34 |
35 | return $this;
36 | }
37 |
38 | public function getName(): string
39 | {
40 | return $this->name;
41 | }
42 |
43 | public function getContents(): string
44 | {
45 | return $this->contents;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/MigrationFile/Stub/MigrationCreateStub.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | public function getNamespaces(): array;
15 | }
16 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/MigrationFile/Stub/MigrationUpdateStub.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | public function getNamespaces(): array;
15 | }
16 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/ForeignKey/ForeignKey.php:
--------------------------------------------------------------------------------
1 | $attributes
20 | * @return static
21 | */
22 | public static function factory(array $attributes): self
23 | {
24 | return new self(
25 | Reference::factory($attributes),
26 | ReferenceAction::factory($attributes)
27 | );
28 | }
29 |
30 | public function makeUpMigration(): string
31 | {
32 | return sprintf('$table%s%s;', $this->reference->makeForeignMigration(), $this->referenceAction->makeForeignMigration());
33 | }
34 |
35 | public function makeDownMigration(): string
36 | {
37 | return sprintf('$table%s;', $this->reference->makeDropForeignMigration());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/ForeignKey/ForeignKeyList.php:
--------------------------------------------------------------------------------
1 | $attributes
13 | */
14 | public function __construct(private array $attributes)
15 | {
16 | }
17 |
18 | public function exists(): bool
19 | {
20 | return ! (empty($this->attributes));
21 | }
22 |
23 | public function makeUpMigration(): string
24 | {
25 | $str = '';
26 |
27 | foreach ($this->attributes as $foreignKey) {
28 | $str .= $foreignKey->makeUpMigration() . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
29 | }
30 |
31 | return trim($str);
32 | }
33 |
34 | public function makeDownMigration(): string
35 | {
36 | $str = '';
37 |
38 | foreach ($this->attributes as $foreignKey) {
39 | $str .= $foreignKey->makeDownMigration() . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
40 | }
41 |
42 | return trim($str);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/ForeignKey/Reference.php:
--------------------------------------------------------------------------------
1 | $columns
16 | * @param array $references
17 | */
18 | private function __construct(
19 | private array $columns,
20 | private array $references,
21 | private string $table,
22 | private ?string $name,
23 | ) {
24 | }
25 |
26 | /**
27 | * @param array $attributes
28 | * @return static
29 | */
30 | public static function factory(array $attributes): self
31 | {
32 | $attributes['columns'] ?? throw new InvalidArgumentException('foreign_keys.columns field is required');
33 | $attributes['references'] ?? throw new InvalidArgumentException('foreign_keys.references field is required');
34 | $attributes['table'] ?? throw new InvalidArgumentException('foreign_keys.table field is required');
35 |
36 | return new self(
37 | is_string($attributes['columns']) ? self::parse($attributes['columns']) : $attributes['columns'],
38 | is_string($attributes['references']) ? self::parse($attributes['references']) : $attributes['references'],
39 | $attributes['table'],
40 | $attributes['name'] ?? null
41 | );
42 | }
43 |
44 | public function makeForeignMigration(): string
45 | {
46 | if ($this->name) {
47 | return sprintf("->foreign(%s, '%s')->references(%s)->on('%s')", $this->makeColumnsMigration(), $this->name, $this->makeReferencesMigration(), $this->table);
48 | }
49 |
50 | return sprintf("->foreign(%s)->references(%s)->on('%s')", $this->makeColumnsMigration(), $this->makeReferencesMigration(), $this->table);
51 | }
52 |
53 | public function makeDropForeignMigration(): string
54 | {
55 | if ($this->name) {
56 | return sprintf("->dropForeign('%s')", $this->name);
57 | }
58 |
59 | return sprintf("->dropForeign(['%s'])", implode("', '", $this->columns));
60 | }
61 |
62 | public function hasName(): bool
63 | {
64 | return $this->name !== null;
65 | }
66 |
67 | public function getName(): ?string
68 | {
69 | return $this->name;
70 | }
71 |
72 | private function makeColumnsMigration(): string
73 | {
74 | if (count($this->columns) > 1) {
75 | return sprintf("['%s']", implode("', '", $this->columns));
76 | }
77 |
78 | return sprintf("'%s'", implode('', $this->columns));
79 | }
80 |
81 | private function makeReferencesMigration(): string
82 | {
83 | if (count($this->references) > 1) {
84 | return sprintf("['%s']", implode("', '", $this->references));
85 | }
86 |
87 | return sprintf("'%s'", implode('', $this->references));
88 | }
89 |
90 | /**
91 | * @return array
92 | */
93 | private static function parse(string $columns): array
94 | {
95 | return array_map(fn ($column) => trim($column), explode(',', $columns));
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/ForeignKey/ReferenceAction.php:
--------------------------------------------------------------------------------
1 | $attributes
20 | * @return static
21 | */
22 | public static function factory(array $attributes): self
23 | {
24 | return new self(
25 | $attributes['onUpdateAction'] ?? null,
26 | $attributes['onDeleteAction'] ?? null,
27 | );
28 | }
29 |
30 | public function makeForeignMigration(): string
31 | {
32 | $str = '';
33 |
34 | if ($this->onUpdateAction) {
35 | $str .= sprintf("->onUpdate('%s')", $this->onUpdateAction);
36 | }
37 |
38 | if ($this->onDeleteAction) {
39 | $str .= sprintf("->onDelete('%s')", $this->onDeleteAction);
40 | }
41 |
42 | return $str;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/IndexModifier/IndexModifier.php:
--------------------------------------------------------------------------------
1 | $columns
19 | * @param string|null $name = null
20 | * @param string|null $algorithm = null
21 | * @param string|null $language = null
22 | */
23 | private function __construct(
24 | private IndexModifierType $type,
25 | private array $columns,
26 | private ?string $name = null,
27 | private ?string $algorithm = null,
28 | private ?string $language = null,
29 | ) {
30 | }
31 |
32 | /**
33 | * @param array $attributes
34 | * @return static
35 | */
36 | public static function factory(array $attributes): self
37 | {
38 | $attributes['type'] ?? throw new InvalidArgumentException('IndexModifier type field is required');
39 | $attributes['columns'] ?? throw new InvalidArgumentException('IndexModifier columns field is required');
40 |
41 | $indexType = IndexModifierTypeFactory::factory($attributes['type']);
42 | $columns = is_string($attributes['columns']) ? self::parse($attributes['columns']) : $attributes['columns'];
43 | $name = $attributes['name'] ?? null;
44 | $algorithm = $attributes['algorithm'] ?? null;
45 | $language = $attributes['language'] ?? null;
46 |
47 | return new self(
48 | $indexType,
49 | $columns,
50 | $name,
51 | $algorithm,
52 | $language
53 | );
54 | }
55 |
56 | public function makeUpMigration(): string
57 | {
58 | if ($this->hasArgs()) {
59 | return '$table->' . sprintf('%s(%s, %s)%s;', $this->type->getUpMethodName(), $this->getColumns(), $this->makeArgs(), $this->makeLanguage());
60 | }
61 |
62 | return '$table->' . sprintf('%s(%s)%s;', $this->type->getUpMethodName(), $this->getColumns(), $this->makeLanguage());
63 | }
64 |
65 | public function makeDownMigration(): string
66 | {
67 | if ($this->name) {
68 | return '$table->' . sprintf("%s('%s');", $this->type->getDownMethodName(), $this->name);
69 | } elseif (is_array($this->columns)) {
70 | return '$table->' . sprintf("%s(['%s']);", $this->type->getDownMethodName(), implode("', '", $this->columns));
71 | }
72 |
73 | return '$table->' . sprintf("%s(['%s']);", $this->type->getDownMethodName(), $this->columns);
74 | }
75 |
76 | private function getColumns(): string
77 | {
78 | if (count($this->columns) > 1) {
79 | return sprintf("['%s']", implode("', '", $this->columns));
80 | }
81 |
82 | return sprintf("'%s'", implode('', $this->columns));
83 | }
84 |
85 | private function hasArgs(): bool
86 | {
87 | if ($this->name) {
88 | return true;
89 | }
90 |
91 | return (bool) ($this->algorithm);
92 | }
93 |
94 | private function makeArgs(): string
95 | {
96 | if ($this->name && $this->algorithm) {
97 | return sprintf("'%s', '%s'", $this->name, $this->algorithm);
98 | } elseif (empty($this->name) && $this->algorithm) {
99 | return sprintf("null, '%s'", $this->algorithm);
100 | } elseif ($this->name && empty($this->algorithm)) {
101 | return sprintf("'%s'", $this->name);
102 | }
103 |
104 | throw new InvalidArgumentException('Has no args.');
105 | }
106 |
107 | private function makeLanguage(): string
108 | {
109 | if ($this->language === null) {
110 | return '';
111 | }
112 |
113 | return sprintf("->language('%s')", $this->language);
114 | }
115 |
116 | /**
117 | * @return array
118 | */
119 | private static function parse(string $columns): array
120 | {
121 | return array_map(fn ($column) => trim($column), explode(',', $columns));
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/IndexModifier/IndexModifierList.php:
--------------------------------------------------------------------------------
1 | $attributes
13 | */
14 | public function __construct(private array $attributes)
15 | {
16 | }
17 |
18 | public function exists(): bool
19 | {
20 | return ! (empty($this->attributes));
21 | }
22 |
23 | public function makeUpMigration(): string
24 | {
25 | $str = '';
26 |
27 | foreach ($this->attributes as $indexModifier) {
28 | $str .= $indexModifier->makeUpMigration() . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
29 | }
30 |
31 | return trim($str);
32 | }
33 |
34 | public function makeDownMigration(): string
35 | {
36 | $str = '';
37 |
38 | foreach ($this->attributes as $indexModifier) {
39 | $str .= $indexModifier->makeDownMigration() . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
40 | }
41 |
42 | return trim($str);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/IndexModifier/IndexModifierType/FullTextType.php:
--------------------------------------------------------------------------------
1 | IndexType::class,
13 | 'primary' => PrimaryType::class,
14 | 'spatialIndex' => SpatialIndexType::class,
15 | 'unique' => UniqueType::class,
16 | 'fullText' => FullTextType::class,
17 | ];
18 |
19 | public static function factory(string $name): IndexModifierType
20 | {
21 | $class = self::MAPPING_CLASS[$name] ?? throw new InvalidArgumentException(sprintf('%s index modifier type does not exist', $name));
22 |
23 | return new $class();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/IndexModifier/IndexModifierType/IndexType.php:
--------------------------------------------------------------------------------
1 | $attributes
37 | * @return $this
38 | */
39 | public static function factory(TableName $tableName, array $attributes): self
40 | {
41 | $columnList = [];
42 | foreach ($attributes['columns'] ?? [] as $columnName => $columnAttributes) {
43 | $columnList[] = Column::factory(new ColumnName($columnName), $columnAttributes);
44 | }
45 |
46 | $indexModifierList = [];
47 | foreach ($attributes['indexes'] ?? [] as $indexModifierAttributes) {
48 | $indexModifierList[] = IndexModifier::factory($indexModifierAttributes);
49 | }
50 |
51 | $foreignKeyList = [];
52 | foreach ($attributes['foreign_keys'] ?? [] as $foreignKeyAttributes) {
53 | $foreignKeyList[] = ForeignKey::factory($foreignKeyAttributes);
54 | }
55 |
56 | return new self(
57 | Table::factory($tableName, new ColumnList($columnList), $attributes),
58 | new Connection($attributes['connection'] ?? null),
59 | new IndexModifierList($indexModifierList),
60 | new ForeignKeyList($foreignKeyList),
61 | );
62 | }
63 |
64 | public function makeCreateTableMigrationFile(
65 | DatabaseDriver $databaseBuilder,
66 | MigrationCreateStub $migrationCreateStub
67 | ): MigrationFile {
68 | $tableComment = '';
69 | if ($this->hasTableComment() && $databaseBuilder->isEnabledTableComment()) {
70 | $tableComment = $databaseBuilder->makeTableComment($this);
71 | }
72 |
73 | return MigrationFile::factory($this->makeCreateTableMigrationFileName(), $migrationCreateStub->getStub())
74 | ->replace('{{ namespace }}', $this->makeMigrationCreateNamespace($migrationCreateStub->getNamespaces()))
75 | ->replace('{{ connection }}', $this->connection->makeMigration())
76 | ->replace('{{ tableName }}', $this->getTableName())
77 | ->replace('{{ tableComment }}', $tableComment)
78 | ->replace('{{ up }}', $this->table->makeMigration());
79 | }
80 |
81 | public function makeCreateIndexMigrationFile(MigrationUpdateStub $migrationUpdateStub): ?MigrationFile
82 | {
83 | if ($this->indexModifierList->exists() === false) {
84 | return null;
85 | }
86 |
87 | return MigrationFile::factory($this->makeCreateIndexMigrationFileName(), $migrationUpdateStub->getStub())
88 | ->replace('{{ namespace }}', $this->makeMigrationUpdateNamespace($migrationUpdateStub->getNamespaces()))
89 | ->replace('{{ connection }}', $this->connection->makeMigration())
90 | ->replace('{{ table }}', $this->getTableName())
91 | ->replace('{{ up }}', $this->indexModifierList->makeUpMigration())
92 | ->replace('{{ down }}', $this->indexModifierList->makeDownMigration());
93 | }
94 |
95 | public function makeConstraintForeignKeyMigrationFile(MigrationUpdateStub $migrationUpdateStub): ?MigrationFile
96 | {
97 | if ($this->foreignKeyList->exists() === false) {
98 | return null;
99 | }
100 |
101 | return MigrationFile::factory($this->makeConstraintForeignKeyMigrationFileName(), $migrationUpdateStub->getStub())
102 | ->replace('{{ namespace }}', $this->makeMigrationUpdateNamespace($migrationUpdateStub->getNamespaces()))
103 | ->replace('{{ connection }}', $this->connection->makeMigration())
104 | ->replace('{{ table }}', $this->getTableName())
105 | ->replace('{{ up }}', $this->foreignKeyList->makeUpMigration())
106 | ->replace('{{ down }}', $this->foreignKeyList->makeDownMigration());
107 | }
108 |
109 | private function makeCreateTableMigrationFileName(): string
110 | {
111 | return sprintf('1970_01_01_000001_create_%s_table.php', $this->getTableName());
112 | }
113 |
114 | private function makeCreateIndexMigrationFileName(): string
115 | {
116 | return sprintf('1970_01_01_000002_create_%s_index.php', $this->getTableName());
117 | }
118 |
119 | private function makeConstraintForeignKeyMigrationFileName(): string
120 | {
121 | return sprintf('1970_01_01_000003_constraint_%s_foreign_key.php', $this->getTableName());
122 | }
123 |
124 | public function getTableName(): string
125 | {
126 | return $this->table->getTableName();
127 | }
128 |
129 | public function getTableComment(): string
130 | {
131 | return $this->table->getTableComment()->get();
132 | }
133 |
134 | public function hasTableComment(): bool
135 | {
136 | return $this->table->getTableComment()->exists();
137 | }
138 |
139 | public function isDbFacadeUsing(): bool
140 | {
141 | if ($this->table->getTableComment()->exists()) {
142 | return true;
143 | }
144 |
145 | /** @var Column $column */
146 | foreach ($this->table->getColumnList() as $column) {
147 | if ($column->isDbFacadeUsing()) {
148 | return true;
149 | }
150 | }
151 |
152 | return false;
153 | }
154 |
155 | /**
156 | * @param array $namespaces
157 | */
158 | private function makeMigrationCreateNamespace(array $namespaces): string
159 | {
160 | if ($this->isDbFacadeUsing()) {
161 | $namespaces[] = 'use Illuminate\Support\Facades\DB;';
162 | }
163 |
164 | sort($namespaces);
165 |
166 | return implode(PHP_EOL, array_unique($namespaces));
167 | }
168 |
169 | /**
170 | * @param array $namespaces
171 | */
172 | private function makeMigrationUpdateNamespace(array $namespaces): string
173 | {
174 | sort($namespaces);
175 |
176 | return implode(PHP_EOL, array_unique($namespaces));
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/SchemaList.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | final class SchemaList implements IteratorAggregate
16 | {
17 | /**
18 | * @param array $attributes
19 | */
20 | public function __construct(private array $attributes)
21 | {
22 | }
23 |
24 | /**
25 | * @return $this
26 | */
27 | public function merge(self $schemaList): self
28 | {
29 | $tableNames = [];
30 |
31 | foreach ($this->attributes as $attribute) {
32 | $tableNames[] = $attribute->getTableName();
33 | }
34 |
35 | foreach ($schemaList as $schema) {
36 | $schema->getTableName();
37 |
38 | in_array($schema->getTableName(), $tableNames, true) ?: throw new DuplicatedTableNameException(sprintf('[%s] table name is already in use', $schema->getTableName()));
39 | $this->attributes[] = $schema;
40 | }
41 |
42 | return $this;
43 | }
44 |
45 | /**
46 | * @return ArrayIterator
47 | */
48 | public function getIterator(): ArrayIterator
49 | {
50 | return new ArrayIterator($this->attributes);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Charset.php:
--------------------------------------------------------------------------------
1 | value !== null) {
21 | return sprintf("\$table->charset = '%s';", $this->value) . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
22 | }
23 |
24 | return '';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Collation.php:
--------------------------------------------------------------------------------
1 | value !== null) {
21 | return sprintf("\$table->collation = '%s';", $this->value) . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
22 | }
23 |
24 | return '';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/Column.php:
--------------------------------------------------------------------------------
1 | |bool|string|null $attributes
37 | * @return static
38 | */
39 | public static function factory(
40 | ColumnName $columnName,
41 | array|bool|string|null $attributes,
42 | ): self {
43 | if (is_string($attributes)) {
44 | $columnType = ColumnTypeFactory::factory($attributes);
45 |
46 | return new self(
47 | $columnName,
48 | $columnType,
49 | ColumnTypeArgs::factory(null),
50 | new ColumnModifierList([])
51 | );
52 | } elseif (is_bool($attributes)) {
53 | $columnType = ColumnTypeFactory::factory($columnName->getName());
54 |
55 | return new self(
56 | new ColumnName(null),
57 | $columnType,
58 | ColumnTypeArgs::factory(null),
59 | new ColumnModifierList([])
60 | );
61 | } elseif (is_array($attributes)) {
62 | $attributes['type'] ?? throw new InvalidArgumentException(sprintf('columns.%s.type field is required', $columnName->getName()));
63 |
64 | $columnType = ColumnTypeFactory::factory($attributes['type']);
65 |
66 | if ($columnType instanceof BooleanArgsColumnType) {
67 | if (isset($attributes['args'])) {
68 | $args = array_map(fn ($args) => var_export($args, true), $attributes['args'] ?? []);
69 | $columnTypeArgs = ColumnTypeArgs::factory($args);
70 | } else {
71 | $columnTypeArgs = ColumnTypeArgs::factory(null);
72 | }
73 | } else {
74 | $columnTypeArgs = ColumnTypeArgs::factory(
75 | $attributes['args'] ?? null,
76 | $columnType instanceof ArrayArgsColumnType,
77 | $columnType instanceof StringArgsColumnType,
78 | $columnType instanceof NumericArgsColumnType
79 | );
80 | }
81 |
82 | unset($attributes['type'], $attributes['args']);
83 |
84 | $columnModifierList = [];
85 | foreach ($attributes as $modifierName => $modifierValue) {
86 | $columnModifierList[] = ColumnModifierFactory::factory($modifierName, $modifierValue);
87 | }
88 |
89 | if ($columnType instanceof AliasColumnType) {
90 | return new self(
91 | new ColumnName(null),
92 | $columnType,
93 | $columnTypeArgs,
94 | new ColumnModifierList($columnModifierList)
95 | );
96 | }
97 |
98 | return new self(
99 | $columnName,
100 | $columnType,
101 | $columnTypeArgs,
102 | new ColumnModifierList($columnModifierList)
103 | );
104 | }
105 |
106 | $columnType = ColumnTypeFactory::factory($columnName->getName());
107 |
108 | return new self(
109 | new ColumnName(null),
110 | $columnType,
111 | ColumnTypeArgs::factory(null),
112 | new ColumnModifierList([])
113 | );
114 | }
115 |
116 | public function makeMigration(): string
117 | {
118 | $modifierMethod = '';
119 | foreach ($this->modifierList as $modifier) {
120 | if ($modifier->hasColumnModifierArgs()) {
121 | if ($modifier instanceof DbFacadeUsing) {
122 | $modifierMethod .= sprintf('->%s(DB::raw(%s))', $modifier->getName(), $modifier->columnModifierArgs());
123 | } else {
124 | $modifierMethod .= sprintf('->%s(%s)', $modifier->getName(), $modifier->columnModifierArgs());
125 | }
126 | } else {
127 | $modifierMethod .= sprintf('->%s()', $modifier->getName());
128 | }
129 | }
130 |
131 | if ($this->name->hasName() && $this->typeArgs->hasArgs()) {
132 | return '$table->' . sprintf("%s('%s', %s)%s;", $this->type->columnType(), $this->name->getName(), $this->typeArgs->typeArgs(), $modifierMethod);
133 | } elseif ($this->name->hasName() && ! $this->typeArgs->hasArgs()) {
134 | return '$table->' . sprintf("%s('%s')%s;", $this->type->columnType(), $this->name->getName(), $modifierMethod);
135 | } elseif (! $this->name->hasName() && $this->typeArgs->hasArgs()) {
136 | return '$table->' . sprintf('%s(%s);', $this->type->columnType(), $this->typeArgs->typeArgs());
137 | }
138 |
139 | return '$table->' . sprintf('%s();', $this->type->columnType());
140 | }
141 |
142 | public function isDbFacadeUsing(): bool
143 | {
144 | foreach ($this->modifierList as $modifier) {
145 | if ($modifier instanceof DbFacadeUsing) {
146 | return true;
147 | }
148 | }
149 |
150 | return false;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnList.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | final class ColumnList implements IteratorAggregate
15 | {
16 | /**
17 | * @param array $attributes
18 | */
19 | public function __construct(private array $attributes)
20 | {
21 | }
22 |
23 | public function exists(): bool
24 | {
25 | return ! (empty($this->attributes));
26 | }
27 |
28 | /**
29 | * @return ArrayIterator
30 | */
31 | public function getIterator(): ArrayIterator
32 | {
33 | return new ArrayIterator($this->attributes);
34 | }
35 |
36 | public function makeMigration(): string
37 | {
38 | $str = '';
39 |
40 | foreach ($this->attributes as $column) {
41 | $str .= $column->makeMigration() . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
42 | }
43 |
44 | return $str;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/AlwaysModifier.php:
--------------------------------------------------------------------------------
1 | columnModifierArgs !== null;
23 | }
24 |
25 | final public function columnModifierArgs(): string
26 | {
27 | return $this->columnModifierArgs ? $this->columnModifierArgs->columnModifierArgs() : '';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierArgs/BooleanColumnModifierArgs.php:
--------------------------------------------------------------------------------
1 | value, true);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierArgs/ColumnModifierArgs.php:
--------------------------------------------------------------------------------
1 | value;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierArgs/MixedColumnModifierArgs.php:
--------------------------------------------------------------------------------
1 | value)) {
19 | return (string) $this->value;
20 | } elseif (is_bool($this->value)) {
21 | return var_export($this->value, true);
22 | }
23 |
24 | return sprintf("'%s'", $this->value);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierArgs/StringColumnModifierArgs.php:
--------------------------------------------------------------------------------
1 | value);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierFactory.php:
--------------------------------------------------------------------------------
1 | AlwaysModifier::class,
19 | 'autoIncrement' => AutoIncrementModifier::class,
20 | 'charset' => CharsetModifier::class,
21 | 'collation' => CollationModifier::class,
22 | 'comment' => CommentModifier::class,
23 | 'default' => DefaultModifier::class,
24 | 'defaultRaw' => DefaultRawModifier::class,
25 | 'from' => FromModifier::class,
26 | 'generatedAs' => GeneratedAsModifier::class,
27 | 'index' => IndexModifier::class,
28 | 'nullable' => NullableModifier::class,
29 | 'storedAs' => StoredAsModifier::class,
30 | 'unique' => UniqueModifier::class,
31 | 'unsigned' => UnsignedModifier::class,
32 | 'useCurrent' => UseCurrentModifier::class,
33 | 'useCurrentOnUpdate' => UseCurrentOnUpdateModifier::class,
34 | 'virtualAs' => VirtualAsModifier::class,
35 | ];
36 |
37 | public static function factory(string $name, string|bool|int|null $value): ColumnModifier
38 | {
39 | $class = self::MAPPING_CLASS[$name] ?? throw new InvalidArgumentException(sprintf('%s column modifier does not exist', $name));
40 |
41 | if (is_string($value)) {
42 | return new $class(new StringColumnModifierArgs($value));
43 | } elseif (is_bool($value)) {
44 | return new $class(new BooleanColumnModifierArgs($value));
45 | } elseif (is_int($value)) {
46 | return new $class(new IntColumnModifierArgs($value));
47 | }
48 |
49 | return new $class(null);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/ColumnModifierList.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | final class ColumnModifierList implements IteratorAggregate
14 | {
15 | /**
16 | * @param array $attributes
17 | */
18 | public function __construct(private array $attributes)
19 | {
20 | }
21 |
22 | /**
23 | * @return ArrayIterator
24 | */
25 | public function getIterator(): ArrayIterator
26 | {
27 | return new ArrayIterator($this->attributes);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnModifier/CommentModifier.php:
--------------------------------------------------------------------------------
1 | name !== null;
19 | }
20 |
21 | public function getName(): string
22 | {
23 | return (string) $this->name;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnType/AliasColumnType.php:
--------------------------------------------------------------------------------
1 | BigIncrementsType::class,
13 | 'bigInteger' => BigIntegerType::class,
14 | 'binary' => BinaryType::class,
15 | 'boolean' => BooleanType::class,
16 | 'char' => CharType::class,
17 | 'dateTime' => DateTimeType::class,
18 | 'dateTimeTz' => DateTimeTzType::class,
19 | 'date' => DateType::class,
20 | 'decimal' => DecimalType::class,
21 | 'double' => DoubleType::class,
22 | 'enum' => EnumType::class,
23 | 'float' => FloatType::class,
24 | 'foreignId' => ForeignIdType::class,
25 | 'geometryCollection' => GeometryCollectionType::class,
26 | 'geometry' => GeometryType::class,
27 | 'id' => IdType::class,
28 | 'increments' => IncrementsType::class,
29 | 'integer' => IntegerType::class,
30 | 'ipAddress' => IpAddressType::class,
31 | 'jsonb' => JsonbType::class,
32 | 'json' => JsonType::class,
33 | 'lineString' => LineStringType::class,
34 | 'longText' => LongTextType::class,
35 | 'macAddress' => MacAddressType::class,
36 | 'mediumIncrements' => MediumIncrementsType::class,
37 | 'mediumInteger' => MediumIntegerType::class,
38 | 'mediumText' => MediumTextType::class,
39 | 'morphs' => MorphsType::class,
40 | 'multiLineString' => MultiLineStringType::class,
41 | 'multiPoint' => MultiPointType::class,
42 | 'multiPolygon' => MultiPolygonType::class,
43 | 'nullableMorphs' => NullableMorphsType::class,
44 | 'nullableTimestamps' => NullableTimestampsType::class,
45 | 'nullableUuidMorphs' => NullableUuidMorphsType::class,
46 | 'point' => PointType::class,
47 | 'polygon' => PolygonType::class,
48 | 'rememberToken' => RememberTokenType::class,
49 | 'set' => SetType::class,
50 | 'smallIncrements' => SmallIncrementsType::class,
51 | 'smallInteger' => SmallIntegerType::class,
52 | 'softDeletes' => SoftDeletesType::class,
53 | 'softDeletesTz' => SoftDeletesTzType::class,
54 | 'string' => StringType::class,
55 | 'text' => TextType::class,
56 | 'timestamps' => TimestampsType::class,
57 | 'timestampsTz' => TimestampsTzType::class,
58 | 'timestamp' => TimestampType::class,
59 | 'timestampTz' => TimestampTzType::class,
60 | 'time' => TimeType::class,
61 | 'timeTz' => TimeTzType::class,
62 | 'tinyIncrements' => TinyIncrementsType::class,
63 | 'tinyInteger' => TinyIntegerType::class,
64 | 'unsignedBigInteger' => UnsignedBigIntegerType::class,
65 | 'unsignedDecimal' => UnsignedDecimalType::class,
66 | 'unsignedInteger' => UnsignedIntegerType::class,
67 | 'unsignedMediumInteger' => UnsignedMediumIntegerType::class,
68 | 'unsignedSmallInteger' => UnsignedSmallIntegerType::class,
69 | 'unsignedTinyInteger' => UnsignedTinyIntegerType::class,
70 | 'uuidMorphs' => UuidMorphsType::class,
71 | 'uuid' => UuidType::class,
72 | 'year' => YearType::class,
73 | ];
74 |
75 | public static function factory(string $name): ColumnType
76 | {
77 | $class = self::MAPPING_CLASS[$name] ?? throw new InvalidArgumentException(sprintf('%s column type does not exist', $name));
78 |
79 | return new $class();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Column/ColumnType/DateTimeType.php:
--------------------------------------------------------------------------------
1 | trim($args), explode(',', $args));
31 | }
32 |
33 | return new self($args, $isArray, $isString, $isNumeric);
34 | }
35 |
36 | public function hasArgs(): bool
37 | {
38 | return $this->args !== null;
39 | }
40 |
41 | public function typeArgs(): string
42 | {
43 | if (is_array($this->args) && $this->isArray) {
44 | return "['" . implode("', '", $this->args) . "']";
45 | } elseif (is_array($this->args) && $this->isString) {
46 | return "'" . implode("', '", $this->args) . "'";
47 | } elseif (is_array($this->args) && $this->isNumeric) {
48 | return implode(', ', $this->args);
49 | } elseif (is_array($this->args)) {
50 | return implode(', ', $this->args);
51 | } elseif (is_numeric($this->args)) {
52 | return (string) $this->args;
53 | }
54 |
55 | return "'" . $this->args . "'";
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Connection.php:
--------------------------------------------------------------------------------
1 | value !== null) {
19 | return sprintf("connection('%s')->", $this->value);
20 | }
21 |
22 | return '';
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Engine.php:
--------------------------------------------------------------------------------
1 | value !== null) {
21 | return sprintf("\$table->engine = '%s';", $this->value) . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
22 | }
23 |
24 | return '';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Table.php:
--------------------------------------------------------------------------------
1 | $attributes
24 | * @return $this
25 | */
26 | public static function factory(TableName $tableName, ColumnList $columnList, array $attributes): self
27 | {
28 | $tableComment = new TableComment($attributes['comment'] ?? null);
29 | $engine = new Engine($attributes['engine'] ?? null);
30 | $charset = new Charset($attributes['charset'] ?? null);
31 | $collation = new Collation($attributes['collation'] ?? null);
32 | $temporary = new Temporary($attributes['temporary'] ?? false);
33 |
34 | return new self(
35 | $tableName,
36 | $columnList,
37 | $tableComment,
38 | $engine,
39 | $charset,
40 | $collation,
41 | $temporary
42 | );
43 | }
44 |
45 | public function makeMigration(): string
46 | {
47 | return trim(
48 | $this->engine->makeMigration()
49 | . $this->charset->makeMigration()
50 | . $this->collation->makeMigration()
51 | . $this->temporary->makeMigration()
52 | . $this->columnList->makeMigration()
53 | );
54 | }
55 |
56 | public function getTableName(): string
57 | {
58 | return $this->tableName->getName();
59 | }
60 |
61 | public function getColumnList(): ColumnList
62 | {
63 | return $this->columnList;
64 | }
65 |
66 | public function getTableComment(): TableComment
67 | {
68 | return $this->tableComment;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/TableComment.php:
--------------------------------------------------------------------------------
1 | value ?? '';
19 | }
20 |
21 | public function exists(): bool
22 | {
23 | return empty($this->value) === false;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/TableName.php:
--------------------------------------------------------------------------------
1 | name;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Schema/Table/Temporary.php:
--------------------------------------------------------------------------------
1 | enable) {
21 | return '$table->temporary();' . PHP_EOL . MigrationFile::MIGRATION_COLUMN_INDENT;
22 | }
23 |
24 | return '';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Dacapo/Domain/Shared/Exception/Schema/Column/ColumnModifier/InvalidArgumentException.php:
--------------------------------------------------------------------------------
1 | getTableName(), $schema->getTableComment());
21 |
22 | return $str;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/Driver/PostgresqlDatabaseDriver.php:
--------------------------------------------------------------------------------
1 | getTableName(), $schema->getTableComment());
21 |
22 | return $str;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/Driver/SqliteDatabaseDriver.php:
--------------------------------------------------------------------------------
1 | >
14 | */
15 | public array $fileList = [];
16 |
17 | public function save(MigrationFile $migrationFile): void
18 | {
19 | $this->fileList[] = ['fileName' => $migrationFile->getName(), 'fileContents' => $migrationFile->getContents()];
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/LaravelDatabaseMigrationsStorage.php:
--------------------------------------------------------------------------------
1 | filesystem->put(database_path('migrations/' . $migrationFile->getName()), $migrationFile->getContents());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/LaravelDatabaseSchemasStorage.php:
--------------------------------------------------------------------------------
1 | (string) $f->getRealPath(), $this->filesystem->files($this->filePath));
28 |
29 | $schemaBodies = [];
30 |
31 | foreach ($ymlFiles as $ymlFile) {
32 | $parsedYmlFile = Yaml::parseFile($ymlFile);
33 |
34 | if ($parsedYmlFile === null) {
35 | throw new SchemaFileEmptyException(sprintf('%s file is empty.', $ymlFile));
36 | }
37 |
38 | $intersectKeys = array_intersect_key($schemaBodies, $parsedYmlFile);
39 |
40 | if (count($intersectKeys) > 0) {
41 | throw new DuplicatedTableNameException(sprintf('Duplicate table name for `%s` in the schema YAML', implode(', ', array_keys($intersectKeys))));
42 | }
43 |
44 | $schemaBodies = array_merge($schemaBodies, $parsedYmlFile);
45 | }
46 |
47 | $list = [];
48 | foreach ($schemaBodies as $tableName => $tableAttributes) {
49 | $list[] = Schema::factory(new TableName($tableName), $tableAttributes);
50 | }
51 |
52 | return new SchemaList($list);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/Stub/LaravelMigrationCreateStub.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | public function getNamespaces(): array
26 | {
27 | return [
28 | 'use Illuminate\Database\Migrations\Migration;',
29 | 'use Illuminate\Database\Schema\Blueprint;',
30 | 'use Illuminate\Support\Facades\Schema;',
31 | ];
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/Stub/LaravelMigrationUpdateStub.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | public function getNamespaces(): array
26 | {
27 | return [
28 | 'use Illuminate\Database\Migrations\Migration;',
29 | 'use Illuminate\Database\Schema\Blueprint;',
30 | 'use Illuminate\Support\Facades\Schema;',
31 | ];
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Dacapo/Infra/Adapter/Stub/dacapo.migration.create.stub:
--------------------------------------------------------------------------------
1 |
39 | */
40 | public array $bindings = [
41 | MigrationCreateStub::class => LaravelMigrationCreateStub::class,
42 | MigrationUpdateStub::class => LaravelMigrationUpdateStub::class,
43 | DatabaseMigrationsStorage::class => LaravelDatabaseMigrationsStorage::class,
44 | ];
45 |
46 | /**
47 | * @var array
48 | */
49 | private array $commands = [
50 | DacapoInitCommand::class,
51 | DacapoCommand::class,
52 | DacapoClearCommand::class,
53 | DacapoStubPublishCommand::class,
54 | DacapoUninstallCommand::class,
55 | ];
56 |
57 | /**
58 | * @var array
59 | */
60 | private array $databaseDrivers = [
61 | 'mysql' => MysqlDatabaseDriver::class,
62 | 'pgsql' => PostgresqlDatabaseDriver::class,
63 | 'sqlsrv' => SqlsrvDatabaseDriver::class,
64 | 'sqlite' => SqliteDatabaseDriver::class,
65 | ];
66 |
67 | /**
68 | * {@inheritdoc}
69 | */
70 | public function register(): void
71 | {
72 | $this->registerCommands();
73 | $this->registerBindings();
74 | }
75 |
76 | /**
77 | * @return array
78 | */
79 | public function provides()
80 | {
81 | return $this->commands;
82 | }
83 |
84 | private function registerCommands(): void
85 | {
86 | $this->commands($this->commands);
87 | }
88 |
89 | /**
90 | * @throws Exception
91 | */
92 | private function registerBindings(): void
93 | {
94 | foreach ($this->bindings as $abstract => $concrete) {
95 | $this->app->bind($abstract, $concrete);
96 | }
97 |
98 | $this->app->bind(DatabaseDriver::class, $this->concreteDatabaseDriver());
99 | $this->app->bind(DatabaseSchemasStorage::class, function ($app) {
100 | return new LaravelDatabaseSchemasStorage($app->make(Filesystem::class), $app->databasePath('schemas'));
101 | });
102 | }
103 |
104 | /**
105 | * @throws Exception
106 | */
107 | private function concreteDatabaseDriver(): string
108 | {
109 | /** @var Connection $connection */
110 | $connection = $this->app->make(ConnectionInterface::class);
111 | $driver = $connection->getDriverName();
112 |
113 | $this->databaseDrivers[$driver] ?? throw new Exception(sprintf('driver %s is not found.', $driver));
114 |
115 | return $this->databaseDrivers[$driver];
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/tools/phpstan/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 |
--------------------------------------------------------------------------------
/tools/phpstan/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "phpstan/phpstan": "^1.4"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tools/phpstan/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "33c00abd2d1f42b2896a17e02db26936",
8 | "packages": [
9 | {
10 | "name": "phpstan/phpstan",
11 | "version": "1.4.3",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/phpstan/phpstan.git",
15 | "reference": "89d10839dbfc95eeb7da656578b4a899ad2b59b1"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89d10839dbfc95eeb7da656578b4a899ad2b59b1",
20 | "reference": "89d10839dbfc95eeb7da656578b4a899ad2b59b1",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": "^7.1|^8.0"
25 | },
26 | "conflict": {
27 | "phpstan/phpstan-shim": "*"
28 | },
29 | "bin": [
30 | "phpstan",
31 | "phpstan.phar"
32 | ],
33 | "type": "library",
34 | "extra": {
35 | "branch-alias": {
36 | "dev-master": "1.4-dev"
37 | }
38 | },
39 | "autoload": {
40 | "files": [
41 | "bootstrap.php"
42 | ]
43 | },
44 | "notification-url": "https://packagist.org/downloads/",
45 | "license": [
46 | "MIT"
47 | ],
48 | "description": "PHPStan - PHP Static Analysis Tool",
49 | "support": {
50 | "issues": "https://github.com/phpstan/phpstan/issues",
51 | "source": "https://github.com/phpstan/phpstan/tree/1.4.3"
52 | },
53 | "funding": [
54 | {
55 | "url": "https://github.com/ondrejmirtes",
56 | "type": "github"
57 | },
58 | {
59 | "url": "https://github.com/phpstan",
60 | "type": "github"
61 | },
62 | {
63 | "url": "https://www.patreon.com/phpstan",
64 | "type": "patreon"
65 | },
66 | {
67 | "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
68 | "type": "tidelift"
69 | }
70 | ],
71 | "time": "2022-01-28T16:27:17+00:00"
72 | }
73 | ],
74 | "packages-dev": [],
75 | "aliases": [],
76 | "minimum-stability": "stable",
77 | "stability-flags": [],
78 | "prefer-stable": false,
79 | "prefer-lowest": false,
80 | "platform": [],
81 | "platform-dev": [],
82 | "plugin-api-version": "2.0.0"
83 | }
84 |
--------------------------------------------------------------------------------
/tools/pint/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 |
--------------------------------------------------------------------------------
/tools/pint/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "laravel/pint": "^1.3"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tools/pint/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "4533690993f4e04065c4ae08e7094823",
8 | "packages": [
9 | {
10 | "name": "laravel/pint",
11 | "version": "v1.3.0",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/laravel/pint.git",
15 | "reference": "6a2c0927b4f6ad4eadb5a67fe3835fdad108949d"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/laravel/pint/zipball/6a2c0927b4f6ad4eadb5a67fe3835fdad108949d",
20 | "reference": "6a2c0927b4f6ad4eadb5a67fe3835fdad108949d",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "ext-json": "*",
25 | "ext-mbstring": "*",
26 | "ext-tokenizer": "*",
27 | "ext-xml": "*",
28 | "php": "^8.0"
29 | },
30 | "require-dev": {
31 | "friendsofphp/php-cs-fixer": "~3.13.1",
32 | "illuminate/view": "^9.32.0",
33 | "laravel-zero/framework": "^9.2.0",
34 | "mockery/mockery": "^1.5.1",
35 | "nunomaduro/larastan": "^2.2.0",
36 | "nunomaduro/termwind": "^1.14.0",
37 | "pestphp/pest": "^1.22.1"
38 | },
39 | "bin": [
40 | "builds/pint"
41 | ],
42 | "type": "project",
43 | "autoload": {
44 | "psr-4": {
45 | "App\\": "app/",
46 | "Database\\Seeders\\": "database/seeders/",
47 | "Database\\Factories\\": "database/factories/"
48 | }
49 | },
50 | "notification-url": "https://packagist.org/downloads/",
51 | "license": [
52 | "MIT"
53 | ],
54 | "authors": [
55 | {
56 | "name": "Nuno Maduro",
57 | "email": "enunomaduro@gmail.com"
58 | }
59 | ],
60 | "description": "An opinionated code formatter for PHP.",
61 | "homepage": "https://laravel.com",
62 | "keywords": [
63 | "format",
64 | "formatter",
65 | "lint",
66 | "linter",
67 | "php"
68 | ],
69 | "support": {
70 | "issues": "https://github.com/laravel/pint/issues",
71 | "source": "https://github.com/laravel/pint"
72 | },
73 | "time": "2022-12-20T17:16:15+00:00"
74 | }
75 | ],
76 | "packages-dev": [],
77 | "aliases": [],
78 | "minimum-stability": "stable",
79 | "stability-flags": [],
80 | "prefer-stable": false,
81 | "prefer-lowest": false,
82 | "platform": [],
83 | "platform-dev": [],
84 | "plugin-api-version": "2.2.0"
85 | }
86 |
--------------------------------------------------------------------------------