-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from nodestream-proj/0.13
`0.13` Working Branch
- Loading branch information
Showing
50 changed files
with
8,898 additions
and
7,994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cleo.helpers import option | ||
|
||
from ..operations import GenerateSquashedMigration | ||
from .nodestream_command import NodestreamCommand | ||
from .shared_options import PROJECT_FILE_OPTION | ||
|
||
|
||
class SquashMigration(NodestreamCommand): | ||
name = "migrations squash" | ||
description = "Generate a migration for the current project." | ||
options = [ | ||
PROJECT_FILE_OPTION, | ||
option( | ||
"from", | ||
description="The name of the migration to squash from.", | ||
value_required=True, | ||
flag=False, | ||
), | ||
option("to", description="The name of the migration to squash to.", flag=False), | ||
] | ||
|
||
async def handle_async(self): | ||
from_migration_name = self.option("from") | ||
to_migration_name = self.option("to") | ||
migrations = self.get_migrations() | ||
operation = GenerateSquashedMigration( | ||
migrations, | ||
from_migration_name, | ||
to_migration_name, | ||
) | ||
await self.run_operation(operation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from ...schema.migrations import ProjectMigrations | ||
from .operation import NodestreamCommand, Operation | ||
|
||
|
||
class GenerateSquashedMigration(Operation): | ||
def __init__( | ||
self, | ||
migrations: ProjectMigrations, | ||
from_migration_name: str, | ||
to_migration_name: str, | ||
) -> None: | ||
self.migrations = migrations | ||
self.from_migration_name = from_migration_name | ||
self.to_migration_name = to_migration_name | ||
|
||
async def perform(self, command: NodestreamCommand): | ||
from_migration = self.migrations.graph.get_migration(self.from_migration_name) | ||
to_migration = ( | ||
self.migrations.graph.get_migration(self.to_migration_name) | ||
if self.to_migration_name | ||
else None | ||
) | ||
migration, path = self.migrations.create_squash_between( | ||
from_migration, to_migration | ||
) | ||
command.line(f"Generated squashed migration {migration.name}.") | ||
command.line( | ||
f"The migration contains {len(migration.operations)} schema changes." | ||
) | ||
for operation in migration.operations: | ||
command.line(f" - {operation.describe()}") | ||
command.line(f"Migration written to {path}") | ||
command.line("Run `nodestream migrations run` to apply the migration.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.