-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Emit row migration ops as raw sql statements.
- Loading branch information
Showing
5 changed files
with
135 additions
and
66 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,52 @@ | ||
from pytest_mock_resources import create_postgres_fixture | ||
from sqlalchemy import Column, text, types | ||
|
||
from sqlalchemy_declarative_extensions import ( | ||
Row, | ||
Rows, | ||
declarative_database, | ||
register_sqlalchemy_events, | ||
) | ||
from sqlalchemy_declarative_extensions.row.compare import compare_rows | ||
from sqlalchemy_declarative_extensions.sqlalchemy import declarative_base | ||
|
||
_Base = declarative_base() | ||
|
||
|
||
@declarative_database | ||
class Base(_Base): # type: ignore | ||
__abstract__ = True | ||
|
||
|
||
class Foo(Base): | ||
__tablename__ = "foo" | ||
|
||
id = Column(types.Integer(), primary_key=True) | ||
name = Column(types.Unicode(), nullable=True) | ||
|
||
|
||
register_sqlalchemy_events(Base.metadata, rows=True) | ||
|
||
pg = create_postgres_fixture( | ||
scope="function", engine_kwargs={"echo": True}, session=True | ||
) | ||
|
||
|
||
def test_insert_missing(pg): | ||
pg.execute(text("CREATE SCHEMA foo")) | ||
pg.execute(text("SET SEARCH_PATH=foo")) | ||
|
||
Base.metadata.create_all(bind=pg.connection()) | ||
pg.commit() | ||
|
||
rows = Rows(ignore_unspecified=True).are( | ||
Row("foo", id=1, name="qwer"), | ||
) | ||
result = compare_rows(pg.connection(), Base.metadata, rows) | ||
for op in result: | ||
for query in op.render(Base.metadata): | ||
pg.execute(query) | ||
pg.commit() | ||
|
||
result = pg.execute(text("SELECT * FROM foo.foo")).fetchall() | ||
assert result == [(1, "qwer")] |