masonite-framework-orm 3.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- masonite_framework_orm-3.0.1.dist-info/METADATA +87 -0
- masonite_framework_orm-3.0.1.dist-info/RECORD +116 -0
- masonite_framework_orm-3.0.1.dist-info/WHEEL +5 -0
- masonite_framework_orm-3.0.1.dist-info/entry_points.txt +3 -0
- masonite_framework_orm-3.0.1.dist-info/licenses/LICENSE +21 -0
- masonite_framework_orm-3.0.1.dist-info/top_level.txt +1 -0
- masoniteorm/__init__.py +1 -0
- masoniteorm/collection/Collection.py +605 -0
- masoniteorm/collection/__init__.py +1 -0
- masoniteorm/commands/CanOverrideConfig.py +16 -0
- masoniteorm/commands/CanOverrideOptionsDefault.py +22 -0
- masoniteorm/commands/Command.py +6 -0
- masoniteorm/commands/Entry.py +43 -0
- masoniteorm/commands/MakeMigrationCommand.py +57 -0
- masoniteorm/commands/MakeModelCommand.py +78 -0
- masoniteorm/commands/MakeModelDocstringCommand.py +37 -0
- masoniteorm/commands/MakeObserverCommand.py +54 -0
- masoniteorm/commands/MakeSeedCommand.py +54 -0
- masoniteorm/commands/MigrateCommand.py +46 -0
- masoniteorm/commands/MigrateFreshCommand.py +41 -0
- masoniteorm/commands/MigrateRefreshCommand.py +41 -0
- masoniteorm/commands/MigrateResetCommand.py +25 -0
- masoniteorm/commands/MigrateRollbackCommand.py +26 -0
- masoniteorm/commands/MigrateStatusCommand.py +51 -0
- masoniteorm/commands/SeedRunCommand.py +35 -0
- masoniteorm/commands/ShellCommand.py +205 -0
- masoniteorm/commands/__init__.py +18 -0
- masoniteorm/commands/stubs/create_migration.stub +20 -0
- masoniteorm/commands/stubs/create_seed.stub +9 -0
- masoniteorm/commands/stubs/model.stub +9 -0
- masoniteorm/commands/stubs/observer.stub +101 -0
- masoniteorm/commands/stubs/table_migration.stub +19 -0
- masoniteorm/config.py +123 -0
- masoniteorm/connections/BaseConnection.py +101 -0
- masoniteorm/connections/ConnectionFactory.py +59 -0
- masoniteorm/connections/ConnectionResolver.py +132 -0
- masoniteorm/connections/MSSQLConnection.py +176 -0
- masoniteorm/connections/MySQLConnection.py +232 -0
- masoniteorm/connections/PostgresConnection.py +225 -0
- masoniteorm/connections/SQLiteConnection.py +179 -0
- masoniteorm/connections/__init__.py +6 -0
- masoniteorm/exceptions.py +38 -0
- masoniteorm/expressions/__init__.py +1 -0
- masoniteorm/expressions/expressions.py +288 -0
- masoniteorm/factories/Factory.py +112 -0
- masoniteorm/factories/__init__.py +1 -0
- masoniteorm/helpers/__init__.py +0 -0
- masoniteorm/helpers/misc.py +22 -0
- masoniteorm/migrations/Migration.py +330 -0
- masoniteorm/migrations/__init__.py +1 -0
- masoniteorm/models/MigrationModel.py +9 -0
- masoniteorm/models/Model.py +1209 -0
- masoniteorm/models/Model.pyi +1366 -0
- masoniteorm/models/Pivot.py +5 -0
- masoniteorm/models/__init__.py +1 -0
- masoniteorm/observers/ObservesEvents.py +27 -0
- masoniteorm/observers/__init__.py +1 -0
- masoniteorm/pagination/BasePaginator.py +10 -0
- masoniteorm/pagination/LengthAwarePaginator.py +34 -0
- masoniteorm/pagination/SimplePaginator.py +28 -0
- masoniteorm/pagination/__init__.py +2 -0
- masoniteorm/providers/ORMProvider.py +39 -0
- masoniteorm/providers/__init__.py +1 -0
- masoniteorm/query/EagerRelation.py +42 -0
- masoniteorm/query/QueryBuilder.py +2486 -0
- masoniteorm/query/__init__.py +1 -0
- masoniteorm/query/grammars/BaseGrammar.py +1027 -0
- masoniteorm/query/grammars/MSSQLGrammar.py +194 -0
- masoniteorm/query/grammars/MySQLGrammar.py +238 -0
- masoniteorm/query/grammars/PostgresGrammar.py +213 -0
- masoniteorm/query/grammars/SQLiteGrammar.py +228 -0
- masoniteorm/query/grammars/__init__.py +4 -0
- masoniteorm/query/processors/MSSQLPostProcessor.py +58 -0
- masoniteorm/query/processors/MySQLPostProcessor.py +48 -0
- masoniteorm/query/processors/PostgresPostProcessor.py +49 -0
- masoniteorm/query/processors/SQLitePostProcessor.py +49 -0
- masoniteorm/query/processors/__init__.py +4 -0
- masoniteorm/relationships/BaseRelationship.py +161 -0
- masoniteorm/relationships/BelongsTo.py +124 -0
- masoniteorm/relationships/BelongsToMany.py +604 -0
- masoniteorm/relationships/HasMany.py +66 -0
- masoniteorm/relationships/HasManyThrough.py +269 -0
- masoniteorm/relationships/HasOne.py +111 -0
- masoniteorm/relationships/HasOneThrough.py +275 -0
- masoniteorm/relationships/MorphMany.py +152 -0
- masoniteorm/relationships/MorphOne.py +156 -0
- masoniteorm/relationships/MorphTo.py +111 -0
- masoniteorm/relationships/MorphToMany.py +108 -0
- masoniteorm/relationships/__init__.py +10 -0
- masoniteorm/schema/Blueprint.py +1161 -0
- masoniteorm/schema/Column.py +144 -0
- masoniteorm/schema/ColumnDiff.py +0 -0
- masoniteorm/schema/Constraint.py +5 -0
- masoniteorm/schema/ForeignKeyConstraint.py +28 -0
- masoniteorm/schema/Index.py +5 -0
- masoniteorm/schema/Schema.py +359 -0
- masoniteorm/schema/Table.py +94 -0
- masoniteorm/schema/TableDiff.py +86 -0
- masoniteorm/schema/__init__.py +3 -0
- masoniteorm/schema/platforms/MSSQLPlatform.py +367 -0
- masoniteorm/schema/platforms/MySQLPlatform.py +513 -0
- masoniteorm/schema/platforms/Platform.py +97 -0
- masoniteorm/schema/platforms/PostgresPlatform.py +551 -0
- masoniteorm/schema/platforms/SQLitePlatform.py +481 -0
- masoniteorm/schema/platforms/__init__.py +4 -0
- masoniteorm/scopes/BaseScope.py +6 -0
- masoniteorm/scopes/SoftDeleteScope.py +56 -0
- masoniteorm/scopes/SoftDeletesMixin.py +13 -0
- masoniteorm/scopes/TimeStampsMixin.py +12 -0
- masoniteorm/scopes/TimeStampsScope.py +47 -0
- masoniteorm/scopes/UUIDPrimaryKeyMixin.py +8 -0
- masoniteorm/scopes/UUIDPrimaryKeyScope.py +51 -0
- masoniteorm/scopes/__init__.py +8 -0
- masoniteorm/scopes/scope.py +15 -0
- masoniteorm/seeds/Seeder.py +42 -0
- masoniteorm/seeds/__init__.py +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
from inflection import camelize, tableize
|
|
6
|
+
|
|
7
|
+
from .Command import Command
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MakeMigrationCommand(Command):
|
|
11
|
+
"""
|
|
12
|
+
Creates a new migration file.
|
|
13
|
+
|
|
14
|
+
migration
|
|
15
|
+
{name : The name of the migration}
|
|
16
|
+
{--c|create=None : The table to create}
|
|
17
|
+
{--t|table=None : The table to alter}
|
|
18
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def handle(self):
|
|
22
|
+
name = self.argument("name")
|
|
23
|
+
now = datetime.datetime.today()
|
|
24
|
+
|
|
25
|
+
if self.option("create") != "None":
|
|
26
|
+
table = self.option("create")
|
|
27
|
+
stub_file = "create_migration"
|
|
28
|
+
else:
|
|
29
|
+
table = self.option("table")
|
|
30
|
+
stub_file = "table_migration"
|
|
31
|
+
|
|
32
|
+
if table == "None":
|
|
33
|
+
table = tableize(name.replace("create_", "").replace("_table", ""))
|
|
34
|
+
stub_file = "create_migration"
|
|
35
|
+
|
|
36
|
+
migration_directory = self.option("directory")
|
|
37
|
+
|
|
38
|
+
with open(
|
|
39
|
+
os.path.join(
|
|
40
|
+
pathlib.Path(__file__).parent.absolute(),
|
|
41
|
+
f"stubs/{stub_file}.stub",
|
|
42
|
+
)
|
|
43
|
+
) as fp:
|
|
44
|
+
output = fp.read()
|
|
45
|
+
output = output.replace("__MIGRATION_NAME__", camelize(name))
|
|
46
|
+
output = output.replace("__TABLE_NAME__", table)
|
|
47
|
+
|
|
48
|
+
file_name = f"{now.strftime('%Y_%m_%d_%H%M%S')}_{name}.py"
|
|
49
|
+
|
|
50
|
+
with open(
|
|
51
|
+
os.path.join(os.getcwd(), migration_directory, file_name), "w"
|
|
52
|
+
) as fp:
|
|
53
|
+
fp.write(output)
|
|
54
|
+
|
|
55
|
+
self.info(
|
|
56
|
+
f"Migration file created: {os.path.join(migration_directory, file_name)}"
|
|
57
|
+
)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
from inflection import camelize, tableize, underscore
|
|
5
|
+
|
|
6
|
+
from .Command import Command
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MakeModelCommand(Command):
|
|
10
|
+
"""
|
|
11
|
+
Creates a new model file.
|
|
12
|
+
|
|
13
|
+
model
|
|
14
|
+
{name : The name of the model}
|
|
15
|
+
{--m|migration : Optionally create a migration file}
|
|
16
|
+
{--s|seeder : Optionally create a seeder file}
|
|
17
|
+
{--c|create : If the migration file should create a table}
|
|
18
|
+
{--t|table : If the migration file should modify an existing table}
|
|
19
|
+
{--p|pep : Makes the file into pep 8 standards}
|
|
20
|
+
{--d|directory=app : The location of the model directory}
|
|
21
|
+
{--D|migrations-directory=databases/migrations : The location of the migration directory}
|
|
22
|
+
{--S|seeders-directory=databases/seeds : The location of the seeders directory}
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def handle(self):
|
|
26
|
+
name = self.argument("name")
|
|
27
|
+
|
|
28
|
+
model_directory = self.option("directory")
|
|
29
|
+
|
|
30
|
+
with open(
|
|
31
|
+
os.path.join(
|
|
32
|
+
pathlib.Path(__file__).parent.absolute(), "stubs/model.stub"
|
|
33
|
+
)
|
|
34
|
+
) as fp:
|
|
35
|
+
output = fp.read()
|
|
36
|
+
output = output.replace("__CLASS__", camelize(name))
|
|
37
|
+
|
|
38
|
+
if self.option("pep"):
|
|
39
|
+
file_name = f"{underscore(name)}.py"
|
|
40
|
+
else:
|
|
41
|
+
file_name = f"{camelize(name)}.py"
|
|
42
|
+
|
|
43
|
+
full_directory_path = os.path.join(os.getcwd(), model_directory)
|
|
44
|
+
|
|
45
|
+
if os.path.exists(os.path.join(full_directory_path, file_name)):
|
|
46
|
+
self.line(
|
|
47
|
+
f'<error>Model "{name}" Already Exists ({full_directory_path}/{file_name})</error>'
|
|
48
|
+
)
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
os.makedirs(
|
|
52
|
+
os.path.dirname(os.path.join(full_directory_path)), exist_ok=True
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
with open(
|
|
56
|
+
os.path.join(os.getcwd(), model_directory, file_name), "w+"
|
|
57
|
+
) as fp:
|
|
58
|
+
fp.write(output)
|
|
59
|
+
|
|
60
|
+
self.info(f"Model created: {os.path.join(model_directory, file_name)}")
|
|
61
|
+
if self.option("migration"):
|
|
62
|
+
migrations_directory = self.option("migrations-directory")
|
|
63
|
+
if self.option("table"):
|
|
64
|
+
self.call(
|
|
65
|
+
"migration",
|
|
66
|
+
f"update_{tableize(name)}_table --table {tableize(name)} --directory {migrations_directory}",
|
|
67
|
+
)
|
|
68
|
+
else:
|
|
69
|
+
self.call(
|
|
70
|
+
"migration",
|
|
71
|
+
f"create_{tableize(name)}_table --create {tableize(name)} --directory {migrations_directory}",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if self.option("seeder"):
|
|
75
|
+
directory = self.option("seeders-directory")
|
|
76
|
+
self.call(
|
|
77
|
+
"seed", f"{self.argument('name')} --directory {directory}"
|
|
78
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from ..config import load_config
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MakeModelDocstringCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Generate model docstring and type hints (for auto-completion).
|
|
8
|
+
|
|
9
|
+
model:docstring
|
|
10
|
+
{table : The table you want to generate docstring and type hints}
|
|
11
|
+
{--t|type-hints : The table you want to generate docstring and type hints}
|
|
12
|
+
{--c|connection=default : The connection you want to use}
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def handle(self):
|
|
16
|
+
table = self.argument("table")
|
|
17
|
+
DB = load_config(self.option("config")).DB
|
|
18
|
+
|
|
19
|
+
schema = DB.get_schema_builder(self.option("connection"))
|
|
20
|
+
|
|
21
|
+
if not schema.has_table(table):
|
|
22
|
+
return self.line_error(
|
|
23
|
+
f"There is no such table {table} for this connection."
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
self.info(f"Model Docstring for table: {table}")
|
|
27
|
+
print('"""')
|
|
28
|
+
for _, column in schema.get_columns(table).items():
|
|
29
|
+
length = f"({column.length})" if column.length else ""
|
|
30
|
+
default = f" default: {column.default}"
|
|
31
|
+
print(f"{column.name}: {column.column_type}{length}{default}")
|
|
32
|
+
print('"""')
|
|
33
|
+
|
|
34
|
+
if self.option("type-hints"):
|
|
35
|
+
self.info(f"Model Type Hints for table: {table}")
|
|
36
|
+
for name, column in schema.get_columns(table).items():
|
|
37
|
+
print(f" {name}:{column.column_python_type.__name__}")
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
from inflection import camelize, underscore
|
|
5
|
+
|
|
6
|
+
from .Command import Command
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MakeObserverCommand(Command):
|
|
10
|
+
"""
|
|
11
|
+
Creates a new observer file.
|
|
12
|
+
|
|
13
|
+
observer
|
|
14
|
+
{name : The name of the observer}
|
|
15
|
+
{--m|model=None : The name of the model}
|
|
16
|
+
{--d|directory=app/observers : The location of the observers directory}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def handle(self):
|
|
20
|
+
name = self.argument("name")
|
|
21
|
+
model = self.option("model")
|
|
22
|
+
if model == "None":
|
|
23
|
+
model = name
|
|
24
|
+
|
|
25
|
+
observer_directory = self.option("directory")
|
|
26
|
+
|
|
27
|
+
with open(
|
|
28
|
+
os.path.join(
|
|
29
|
+
pathlib.Path(__file__).parent.absolute(), "stubs/observer.stub"
|
|
30
|
+
)
|
|
31
|
+
) as fp:
|
|
32
|
+
output = fp.read()
|
|
33
|
+
output = output.replace("__CLASS__", camelize(name))
|
|
34
|
+
output = output.replace("__MODEL_VARIABLE__", underscore(model))
|
|
35
|
+
output = output.replace("__MODEL__", camelize(model))
|
|
36
|
+
|
|
37
|
+
file_name = f"{camelize(name)}Observer.py"
|
|
38
|
+
|
|
39
|
+
full_directory_path = os.path.join(os.getcwd(), observer_directory)
|
|
40
|
+
|
|
41
|
+
if os.path.exists(os.path.join(full_directory_path, file_name)):
|
|
42
|
+
self.line(
|
|
43
|
+
f'<error>Observer "{name}" Already Exists ({full_directory_path}/{file_name})</error>'
|
|
44
|
+
)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
os.makedirs(os.path.join(full_directory_path), exist_ok=True)
|
|
48
|
+
|
|
49
|
+
with open(
|
|
50
|
+
os.path.join(os.getcwd(), observer_directory, file_name), "w+"
|
|
51
|
+
) as fp:
|
|
52
|
+
fp.write(output)
|
|
53
|
+
|
|
54
|
+
self.info(f"Observer created: {file_name}")
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
from inflection import camelize, underscore
|
|
5
|
+
|
|
6
|
+
from .Command import Command
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MakeSeedCommand(Command):
|
|
10
|
+
"""
|
|
11
|
+
Creates a new seed file.
|
|
12
|
+
|
|
13
|
+
seed
|
|
14
|
+
{name : The name of the seed}
|
|
15
|
+
{--d|directory=databases/seeds : The location of the seed directory}
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def handle(self):
|
|
19
|
+
# get the contents of a stub file
|
|
20
|
+
# replace the placeholders of a stub file
|
|
21
|
+
# output the content to a file location
|
|
22
|
+
name = self.argument("name") + "TableSeeder"
|
|
23
|
+
seed_directory = self.option("directory")
|
|
24
|
+
|
|
25
|
+
file_name = underscore(name)
|
|
26
|
+
stub_file = "create_seed"
|
|
27
|
+
|
|
28
|
+
with open(
|
|
29
|
+
os.path.join(
|
|
30
|
+
pathlib.Path(__file__).parent.absolute(),
|
|
31
|
+
f"stubs/{stub_file}.stub",
|
|
32
|
+
)
|
|
33
|
+
) as fp:
|
|
34
|
+
output = fp.read()
|
|
35
|
+
output = output.replace("__SEEDER_NAME__", camelize(name))
|
|
36
|
+
|
|
37
|
+
file_name = f"{underscore(name)}.py"
|
|
38
|
+
full_path = pathlib.Path(
|
|
39
|
+
os.path.join(os.getcwd(), seed_directory, file_name)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
path_normalized = pathlib.Path(seed_directory) / pathlib.Path(
|
|
43
|
+
file_name
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if os.path.exists(full_path):
|
|
47
|
+
return self.line(
|
|
48
|
+
f"<error>{path_normalized} already exists.</error>"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
with open(full_path, "w") as fp:
|
|
52
|
+
fp.write(output)
|
|
53
|
+
|
|
54
|
+
self.info(f"Seed file created: {path_normalized}")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from ..migrations import Migration
|
|
4
|
+
from .Command import Command
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MigrateCommand(Command):
|
|
8
|
+
"""
|
|
9
|
+
Run migrations.
|
|
10
|
+
|
|
11
|
+
migrate
|
|
12
|
+
{--m|migration=all : Migration's name to be migrated}
|
|
13
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
14
|
+
{--f|force : Force migrations without prompt in production}
|
|
15
|
+
{--s|show : Shows the output of SQL for migrations that would be running}
|
|
16
|
+
{--schema=? : Sets the schema to be migrated}
|
|
17
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def handle(self):
|
|
21
|
+
# prompt user for confirmation in production
|
|
22
|
+
if os.getenv("APP_ENV") == "production" and not self.option("force"):
|
|
23
|
+
answer = ""
|
|
24
|
+
while answer not in ["y", "n"]:
|
|
25
|
+
answer = input(
|
|
26
|
+
"Do you want to run migrations in PRODUCTION ? (y/n)\n"
|
|
27
|
+
).lower()
|
|
28
|
+
if answer != "y":
|
|
29
|
+
self.info("Migrations cancelled")
|
|
30
|
+
exit(0)
|
|
31
|
+
migration = Migration(
|
|
32
|
+
command_class=self,
|
|
33
|
+
connection=self.option("connection"),
|
|
34
|
+
migration_directory=self.option("directory"),
|
|
35
|
+
config_path=self.option("config"),
|
|
36
|
+
schema=self.option("schema"),
|
|
37
|
+
)
|
|
38
|
+
migration.create_table_if_not_exists()
|
|
39
|
+
if not migration.get_unran_migrations():
|
|
40
|
+
self.info("Nothing To Migrate!")
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
migration_name = self.option("migration")
|
|
44
|
+
show_output = self.option("show")
|
|
45
|
+
|
|
46
|
+
migration.migrate(migration=migration_name, output=show_output)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from ..migrations import Migration
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MigrateFreshCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Drops all tables and migrates them again.
|
|
8
|
+
|
|
9
|
+
migrate:fresh
|
|
10
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
11
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
12
|
+
{--f|ignore-fk=? : The connection you want to run migrations on}
|
|
13
|
+
{--s|seed=? : Seed database after fresh. The seeder to be ran can be provided in argument}
|
|
14
|
+
{--schema=? : Sets the schema to be migrated}
|
|
15
|
+
{--D|seed-directory=databases/seeds : The location of the seed directory if seed option is used.}
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def handle(self):
|
|
19
|
+
migration = Migration(
|
|
20
|
+
command_class=self,
|
|
21
|
+
connection=self.option("connection"),
|
|
22
|
+
migration_directory=self.option("directory"),
|
|
23
|
+
config_path=self.option("config"),
|
|
24
|
+
schema=self.option("schema"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
migration.fresh(ignore_fk=self.option("ignore-fk"))
|
|
28
|
+
|
|
29
|
+
self.line("")
|
|
30
|
+
|
|
31
|
+
if self.option("seed") == "null":
|
|
32
|
+
self.call(
|
|
33
|
+
"seed:run",
|
|
34
|
+
f"None --directory {self.option('seed-directory')} --connection {self.option('connection')}",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
elif self.option("seed"):
|
|
38
|
+
self.call(
|
|
39
|
+
"seed:run",
|
|
40
|
+
f"{self.option('seed')} --directory {self.option('seed-directory')} --connection {self.option('connection')}",
|
|
41
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from ..migrations import Migration
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MigrateRefreshCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Rolls back migrations and migrates them again.
|
|
8
|
+
|
|
9
|
+
migrate:refresh
|
|
10
|
+
{--m|migration=all : Migration's name to be refreshed}
|
|
11
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
12
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
13
|
+
{--s|seed=? : Seed database after refresh. The seeder to be ran can be provided in argument}
|
|
14
|
+
{--schema=? : Sets the schema to be migrated}
|
|
15
|
+
{--D|seed-directory=databases/seeds : The location of the seed directory if seed option is used.}
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def handle(self):
|
|
19
|
+
migration = Migration(
|
|
20
|
+
command_class=self,
|
|
21
|
+
connection=self.option("connection"),
|
|
22
|
+
migration_directory=self.option("directory"),
|
|
23
|
+
config_path=self.option("config"),
|
|
24
|
+
schema=self.option("schema"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
migration.refresh(self.option("migration"))
|
|
28
|
+
|
|
29
|
+
self.line("")
|
|
30
|
+
|
|
31
|
+
if self.option("seed") == "null":
|
|
32
|
+
self.call(
|
|
33
|
+
"seed:run",
|
|
34
|
+
f"None --directory {self.option('seed-directory')} --connection {self.option('connection')}",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
elif self.option("seed"):
|
|
38
|
+
self.call(
|
|
39
|
+
"seed:run",
|
|
40
|
+
f"{self.option('seed')} --directory {self.option('seed-directory')} --connection {self.option('connection')}",
|
|
41
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from ..migrations import Migration
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MigrateResetCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Reset migrations.
|
|
8
|
+
|
|
9
|
+
migrate:reset
|
|
10
|
+
{--m|migration=all : Migration's name to be rollback}
|
|
11
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
12
|
+
{--schema=? : Sets the schema to be migrated}
|
|
13
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def handle(self):
|
|
17
|
+
migration = Migration(
|
|
18
|
+
command_class=self,
|
|
19
|
+
connection=self.option("connection"),
|
|
20
|
+
migration_directory=self.option("directory"),
|
|
21
|
+
config_path=self.option("config"),
|
|
22
|
+
schema=self.option("schema"),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
migration.reset(self.option("migration"))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from ..migrations import Migration
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MigrateRollbackCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Rolls back the last batch of migrations.
|
|
8
|
+
|
|
9
|
+
migrate:rollback
|
|
10
|
+
{--m|migration=all : Migration's name to be rollback}
|
|
11
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
12
|
+
{--s|show : Shows the output of SQL for migrations that would be running}
|
|
13
|
+
{--schema=? : Sets the schema to be migrated}
|
|
14
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def handle(self):
|
|
18
|
+
Migration(
|
|
19
|
+
command_class=self,
|
|
20
|
+
connection=self.option("connection"),
|
|
21
|
+
migration_directory=self.option("directory"),
|
|
22
|
+
config_path=self.option("config"),
|
|
23
|
+
schema=self.option("schema"),
|
|
24
|
+
).rollback(
|
|
25
|
+
migration=self.option("migration"), output=self.option("show")
|
|
26
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from ..migrations import Migration
|
|
2
|
+
from .Command import Command
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MigrateStatusCommand(Command):
|
|
6
|
+
"""
|
|
7
|
+
Display migrations status.
|
|
8
|
+
|
|
9
|
+
migrate:status
|
|
10
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
11
|
+
{--schema=? : Sets the schema to be migrated}
|
|
12
|
+
{--d|directory=databases/migrations : The location of the migration directory}
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def handle(self):
|
|
16
|
+
migration = Migration(
|
|
17
|
+
command_class=self,
|
|
18
|
+
connection=self.option("connection"),
|
|
19
|
+
migration_directory=self.option("directory"),
|
|
20
|
+
config_path=self.option("config"),
|
|
21
|
+
schema=self.option("schema"),
|
|
22
|
+
)
|
|
23
|
+
migration.create_table_if_not_exists()
|
|
24
|
+
table = self.table()
|
|
25
|
+
table.set_header_row(["Ran?", "Migration", "Batch"])
|
|
26
|
+
migrations = []
|
|
27
|
+
|
|
28
|
+
for migration_data in migration.get_ran_migrations():
|
|
29
|
+
migration_file = migration_data["migration_file"]
|
|
30
|
+
batch = migration_data["batch"]
|
|
31
|
+
|
|
32
|
+
migrations.append(
|
|
33
|
+
[
|
|
34
|
+
"<info>Y</info>",
|
|
35
|
+
f"<comment>{migration_file}</comment>",
|
|
36
|
+
f"<info>{batch}</info>",
|
|
37
|
+
]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
for migration_file in migration.get_unran_migrations():
|
|
41
|
+
migrations.append(
|
|
42
|
+
[
|
|
43
|
+
"<error>N</error>",
|
|
44
|
+
f"<comment>{migration_file}</comment>",
|
|
45
|
+
"<info>-</info>",
|
|
46
|
+
]
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
table.set_rows(migrations)
|
|
50
|
+
|
|
51
|
+
table.render(self.io)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from inflection import camelize, underscore
|
|
2
|
+
|
|
3
|
+
from ..seeds import Seeder
|
|
4
|
+
from .Command import Command
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SeedRunCommand(Command):
|
|
8
|
+
"""
|
|
9
|
+
Run seeds.
|
|
10
|
+
|
|
11
|
+
seed:run
|
|
12
|
+
{--c|connection=default : The connection you want to run migrations on}
|
|
13
|
+
{--dry : If the seed should run in dry mode}
|
|
14
|
+
{table=None : Name of the table to seed}
|
|
15
|
+
{--d|directory=databases/seeds : The location of the seed directory}
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def handle(self):
|
|
19
|
+
seeder = Seeder(
|
|
20
|
+
dry=self.option("dry"),
|
|
21
|
+
seed_path=self.option("directory"),
|
|
22
|
+
connection=self.option("connection"),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if self.argument("table") == "None":
|
|
26
|
+
seeder.run_database_seed()
|
|
27
|
+
seeder_seeded = "Database Seeder"
|
|
28
|
+
|
|
29
|
+
else:
|
|
30
|
+
table = self.argument("table")
|
|
31
|
+
seeder_file = f"{underscore(table)}_table_seeder.{camelize(table)}TableSeeder"
|
|
32
|
+
seeder.run_specific_seed(seeder_file)
|
|
33
|
+
seeder_seeded = f"{camelize(table)}TableSeeder"
|
|
34
|
+
|
|
35
|
+
self.line(f"<info>{seeder_seeded} seeded!</info>")
|