diff --git a/dynamicannotationdb/annotation.py b/dynamicannotationdb/annotation.py index 53c8aa8..418670e 100644 --- a/dynamicannotationdb/annotation.py +++ b/dynamicannotationdb/annotation.py @@ -55,6 +55,7 @@ def create_table( with_crud_columns: bool = True, read_permission: str = "PUBLIC", write_permission: str = "PRIVATE", + keep_created_ts_col: bool = False, notice_text: str = None, ): r"""Create new annotation table unless already exists @@ -144,6 +145,7 @@ def create_table( "read_permission": read_permission, "write_permission": write_permission, "last_modified": creation_time, + "keep_created_ts_col": keep_created_ts_col, "notice_text": notice_text, } diff --git a/dynamicannotationdb/migration/alembic/versions/4654f43b80f6_add_keep_created_ts_col.py b/dynamicannotationdb/migration/alembic/versions/4654f43b80f6_add_keep_created_ts_col.py new file mode 100644 index 0000000..b5198f9 --- /dev/null +++ b/dynamicannotationdb/migration/alembic/versions/4654f43b80f6_add_keep_created_ts_col.py @@ -0,0 +1,31 @@ +"""Add keep created ts col + +Revision ID: 4654f43b80f6 +Revises: 309cf493a1e2 +Create Date: 2023-01-17 17:16:11.658225 + +""" +from alembic import op +import sqlalchemy as sa + +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "4654f43b80f6" +down_revision = "309cf493a1e2" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column( + "annotation_table_metadata", + sa.Column("keep_created_ts_col", sa.Boolean(), nullable=True), + ) + + op.execute("UPDATE annotation_table_metadata SET keep_created_ts_col = False") + op.alter_column("annotation_table_metadata", "keep_created_ts_col", nullable=False) + + +def downgrade(): + op.drop_column("annotation_table_metadata", "keep_created_ts_col") diff --git a/dynamicannotationdb/migration/migrate.py b/dynamicannotationdb/migration/migrate.py index 8a423b6..9c61e3b 100644 --- a/dynamicannotationdb/migration/migrate.py +++ b/dynamicannotationdb/migration/migrate.py @@ -219,8 +219,11 @@ def apply_cascade_option_to_tables(self, dry_run: bool = True): raise error return fkey_mappings - def add_cascade_delete_to_fkey(self, table: Table, dry_run: bool = True): - table_name = table.name + def add_cascade_delete_to_fkey(self, table: Table or str, dry_run: bool = True): + if isinstance(table, str): + table_name = table + else: + table_name = table.table fkeys_to_drop = {} fkey_to_add = {} for fk in self.target_inspector.get_foreign_keys(table_name): diff --git a/dynamicannotationdb/models.py b/dynamicannotationdb/models.py index 23b3a4a..e30054e 100644 --- a/dynamicannotationdb/models.py +++ b/dynamicannotationdb/models.py @@ -18,8 +18,6 @@ from sqlalchemy.orm import relationship from sqlalchemy.dialects import postgresql -# Models that will be created in the 'materialized' database. -MatBase = declarative_base() # Models that will be created in the 'annotation' database. AnnotationBase = declarative_base() @@ -87,17 +85,6 @@ class VersionErrorTable(Base): analysisversion = relationship("AnalysisVersion") -class MaterializedMetadata(MatBase): - __tablename__ = "materializedmetadata" - id = Column(Integer, primary_key=True) - schema = Column(String(100), nullable=False) - table_name = Column(String(100), nullable=False) - row_count = Column(Integer, nullable=False) - materialized_timestamp = Column(DateTime, nullable=False) - segmentation_source = Column(String(255), nullable=True) - is_merged = Column(Boolean, nullable=True) - - class AnnoMetadata(Base): __tablename__ = "annotation_table_metadata" id = Column(Integer, primary_key=True) @@ -123,6 +110,7 @@ class AnnoMetadata(Base): nullable=False, ) last_modified = Column(DateTime, nullable=False) + keep_created_ts_col = Column(Boolean, nullable=False) class SegmentationMetadata(Base):