Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- add test for plain name in hashed migration template
- fix double section in migrations.md
  • Loading branch information
devkral committed Dec 16, 2024
1 parent 1bbc5cc commit b362d5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
33 changes: 11 additions & 22 deletions docs/migrations/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,25 @@ The parameters availabe when using instantiating a [Instance](#migration) object
of `edgy.Registry` or an `AssertationError` is raised.
* **app** - Optionally an application instance.

### Settings
## Migration Settings

The following settings are available in the main settings object:
Migrations use now the edgy settings. Here are all knobs you need to configure them.
All settings are in `edgy/conf/global_settings.py`.

- multi_schema (bool / regexstring / regexpattern) - Activate multi schema migrations (Default: False).
- ignore_schema_pattern (None / regexstring / regexpattern) - When using multi schema migrations, ignore following regex pattern (Default "information_schema")
- alembic_ctx_kwargs (dict) - Extra arguments for alembic. By default:
Some important settings are:

- `multi_schema` (bool / regexstring / regexpattern) - (Default: False). Activate multi schema migrations. `True` for all schemes, a regex for some schemes.
- `ignore_schema_pattern` (None / regexstring / regexpattern) - (Default: "information_schema"). When using multi schema migrations, ignore following regex pattern (Default "information_schema")
- `migrate_databases` - (Default: (None,)) Databases which should be migrated.
- `migration_directory` - (Default: "migrations"). Path to the alembic migration folder.
This overwritable per command via `-d`, `--directory` parameter.
- `alembic_ctx_kwargs` (dict) - Extra arguments for alembic. By default:
``` python
{
"compare_type": True,
"render_as_batch": True,
}
```
- migration_directory (str / PathLike) - Migrations directory. Absolute or relative. By default: "migrations".



### How to use it

Expand Down Expand Up @@ -609,17 +612,3 @@ def downgrade(engine_name: str = ""):

If you want to migrate multiple schemes you just have to turn on `multi_schema` in the [Migration settings](#migration-settings).
You might want to filter via the schema parameters what schemes should be migrated.

## Migration Settings

Migrations use now the edgy settings. Here are all knobs you need to configure them.
Basically all settings are in `edgy/conf/global_settings.py`.

Some important settings are:

- `multi_schema` - (Default: False). Include the schemes in the migrations, `True` for all schemes, a regex for some schemes.
- `ignore_schema_pattern` - (Default: "information_schema"). Exclude patterns for `multi_schema`.
- `migrate_databases` - (Default: (None,)) Databases which should be migrated.
- `migration_directory` - (Default: "migrations"). Path to the alembic migration folder.
This overwritable per command via `-d`, `--directory` parameter.
- `alembic_ctx_kwargs` - (Default: `{"compare_type": True, "render_as_batch": True}`). Extra arguments for alembic.
12 changes: 12 additions & 0 deletions tests/cli/test_multidb_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ async def test_migrate_upgrade_multidb(app_flag, template_param):
extra_env={"EDGY_SETTINGS_MODULE": "tests.settings.multidb.TestSettings"},
)
assert ss == 0
migrations = list((base_path / "migrations" / "versions").glob("*.py"))
assert len(migrations) == 0

(o, e, ss) = await arun_cmd(
"tests.cli.main_multidb",
Expand All @@ -106,6 +108,12 @@ async def test_migrate_upgrade_multidb(app_flag, template_param):
)
assert ss == 0

migrations = list((base_path / "migrations" / "versions").glob("*.py"))
assert len(migrations) == 1
if "custom" not in template_param and "plain" not in template_param:
assert '"another"' in migrations[0].read_text()
assert "main database" in migrations[0].read_text()

if "custom" in template_param:
with open("migrations/README") as f:
assert f.readline().strip() == "Custom template"
Expand Down Expand Up @@ -148,10 +156,14 @@ async def test_multidb_nonidentifier(template_param):
extra_env={"EDGY_SETTINGS_MODULE": "tests.settings.multidb_nonidentifier.TestSettings"},
)
if "plain" in template_param:
# this has to break, luckily alembic checks migrations
assert ss == 1
else:
assert ss == 0
assert b"No changes in schema detected" not in o
migrations = list((base_path / "migrations" / "versions").glob("*.py"))
assert len(migrations) == 1
assert '"ano ther "' in migrations[0].read_text()


@pytest.mark.parametrize("app_flag", ["explicit", "explicit_env"])
Expand Down
5 changes: 5 additions & 0 deletions tests/cli/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ async def test_migrate_upgrade(app_flag, template_param):
)
assert ss == 0

migrations = list((base_path / "migrations" / "versions").glob("*.py"))
assert len(migrations) == 1
if "custom" not in template_param and "plain" not in template_param:
assert "main database" in migrations[0].read_text()

(o, e, ss) = await arun_cmd(
"tests.cli.main",
f"hatch run python {__file__} test_migrate_upgrade",
Expand Down

0 comments on commit b362d5f

Please sign in to comment.