-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #7 from DanCardin/dc/schema-create-order
- Loading branch information
Showing
11 changed files
with
140 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[alembic] | ||
script_location = migrations | ||
|
||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
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,9 @@ | ||
import pytest | ||
from pytest_mock_resources import create_postgres_fixture, PostgresConfig | ||
|
||
alembic_engine = create_postgres_fixture(scope="function", engine_kwargs={"echo": True}) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def pmr_postgres_config(): | ||
return PostgresConfig(port=None, ci_port=None) |
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,27 @@ | ||
from alembic import context | ||
from sqlalchemy import engine_from_config, pool | ||
|
||
# isort: split | ||
from models import Base | ||
|
||
from sqlalchemy_declarative_extensions.alembic import register_alembic_events | ||
|
||
target_metadata = Base.metadata | ||
|
||
register_alembic_events(schemas=True, roles=True, grants=True) | ||
|
||
|
||
connectable = context.config.attributes.get("connection", None) | ||
|
||
if connectable is None: | ||
connectable = engine_from_config( | ||
context.config.get_section(context.config.config_ini_section), | ||
prefix="sqlalchemy.", | ||
poolclass=pool.NullPool, | ||
) | ||
|
||
with connectable.connect() as connection: | ||
context.configure(connection=connection, target_metadata=target_metadata) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() |
24 changes: 24 additions & 0 deletions
24
tests/examples/test_grant_after_schema/migrations/script.py.mako
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,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
|
||
def upgrade(): | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade(): | ||
${downgrades if downgrades else "pass"} |
Empty file.
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,17 @@ | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
from sqlalchemy_declarative_extensions import declarative_database, Roles, Schemas | ||
from sqlalchemy_declarative_extensions.dialects.postgresql import DefaultGrant | ||
|
||
_Base = declarative_base() | ||
|
||
|
||
@declarative_database | ||
class Base(_Base): | ||
__abstract__ = True | ||
|
||
schemas = Schemas().are("foo") | ||
roles = Roles(ignore_unspecified=True).are("bar") | ||
grants = [ | ||
DefaultGrant.on_tables_in_schema("foo").grant("select", to="bar"), | ||
] |
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,12 @@ | ||
from pytest_alembic import MigrationContext, tests | ||
|
||
|
||
def test_apply_autogenerated_revision(alembic_runner: MigrationContext, alembic_engine): | ||
result = alembic_runner.generate_revision( | ||
autogenerate=True, prevent_file_generation=False | ||
) | ||
alembic_runner.migrate_up_one() | ||
|
||
# Verify this no longer sees changes to make! Failing here would imply the autogenerate | ||
# is not fully normalizing the difference. | ||
tests.test_model_definitions_match_ddl(alembic_runner) |
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