-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e2569
commit a4f514a
Showing
1 changed file
with
125 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import enum | ||
from typing import TYPE_CHECKING | ||
|
||
import sqlalchemy | ||
|
||
if TYPE_CHECKING: | ||
from sqlalchemy import Connection | ||
from sqlalchemy import MetaData, Column, Integer, insert | ||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
from tests.base.run_migration_test_abc import CompareAndRunTestCase | ||
|
||
|
||
class TestMigrationHangUp(CompareAndRunTestCase): | ||
"""https://github.com/Pogchamp-company/alembic-postgresql-enum/issues/102""" | ||
|
||
def get_database_schema(self) -> MetaData: | ||
my_metadata = MetaData() | ||
|
||
class Base(DeclarativeBase): | ||
metadata = my_metadata | ||
|
||
class VideoState(enum.Enum): | ||
NOT_RECORDED = 0 | ||
RECORDED = 1 | ||
VALIDATION_WAITING = 2 | ||
VALIDATED = 3 | ||
MARKUP_WAITING = 4 | ||
MARKED = 5 | ||
IN_PROCESS = 6 | ||
PROCESSED = 7 | ||
RECLASSIFICATION_WAITING = 8 | ||
RECLASSIFIED = 9 | ||
DONE = 10 | ||
|
||
class Video(Base): | ||
__tablename__ = "videos" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
state = Column( | ||
sqlalchemy.Enum(VideoState), | ||
nullable=False, | ||
server_default=VideoState.NOT_RECORDED.name, | ||
default=VideoState.NOT_RECORDED, | ||
) | ||
|
||
return my_metadata | ||
|
||
def get_target_schema(self) -> MetaData: | ||
my_metadata = MetaData() | ||
|
||
class Base(DeclarativeBase): | ||
metadata = my_metadata | ||
|
||
class VideoState(enum.Enum): | ||
NOT_RECORDED = 0 | ||
RECORDED = 1 | ||
VALIDATION_WAITING = 2 | ||
VALIDATED = 3 | ||
MARKUP_WAITING = 4 | ||
MARKED = 5 | ||
IN_PROCESS = 6 | ||
PROCESSED = 7 | ||
RECLASSIFICATION_WAITING = 8 | ||
RECLASSIFIED = 9 | ||
DONE = 10 | ||
SAD = 11 | ||
|
||
class Video(Base): | ||
__tablename__ = "videos" | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
state = Column( | ||
sqlalchemy.Enum(VideoState), | ||
nullable=False, | ||
server_default=VideoState.NOT_RECORDED.name, | ||
default=VideoState.NOT_RECORDED, | ||
) | ||
|
||
return my_metadata | ||
|
||
def insert_migration_data(self, connection: "Connection", database_schema: MetaData) -> None: | ||
videos_table = database_schema.tables["videos"] | ||
connection.execute( | ||
insert(videos_table).values( | ||
[ | ||
{"state": "NOT_RECORDED"}, | ||
{"state": "RECORDED"}, | ||
{"state": "VALIDATION_WAITING"}, | ||
{"state": "VALIDATED"}, | ||
{"state": "MARKUP_WAITING"}, | ||
{"state": "MARKED"}, | ||
{"state": "IN_PROCESS"}, | ||
{"state": "PROCESSED"}, | ||
{"state": "RECLASSIFICATION_WAITING"}, | ||
{"state": "RECLASSIFIED"}, | ||
{"state": "DONE"}, | ||
{"state": "RECORDED"}, | ||
] | ||
) | ||
) | ||
|
||
def get_expected_upgrade(self) -> str: | ||
return """ | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values( | ||
enum_schema='public', | ||
enum_name='videostate', | ||
new_values=['NOT_RECORDED', 'RECORDED', 'VALIDATION_WAITING', 'VALIDATED', 'MARKUP_WAITING', 'MARKED', 'IN_PROCESS', 'PROCESSED', 'RECLASSIFICATION_WAITING', 'RECLASSIFIED', 'DONE', 'SAD'], | ||
affected_columns=[TableReference(table_schema='public', table_name='videos', column_name='state', existing_server_default="'NOT_RECORDED'::videostate")], | ||
enum_values_to_rename=[], | ||
) | ||
# ### end Alembic commands ### | ||
""" | ||
|
||
def get_expected_downgrade(self) -> str: | ||
return """ | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values( | ||
enum_schema='public', | ||
enum_name='videostate', | ||
new_values=['NOT_RECORDED', 'RECORDED', 'VALIDATION_WAITING', 'VALIDATED', 'MARKUP_WAITING', 'MARKED', 'IN_PROCESS', 'PROCESSED', 'RECLASSIFICATION_WAITING', 'RECLASSIFIED', 'DONE'], | ||
affected_columns=[TableReference(table_schema='public', table_name='videos', column_name='state', existing_server_default="'NOT_RECORDED'::videostate")], | ||
enum_values_to_rename=[], | ||
) | ||
# ### end Alembic commands ### | ||
""" |