-
Notifications
You must be signed in to change notification settings - Fork 20
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
c641de5
commit c506ec7
Showing
5 changed files
with
101 additions
and
10 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
32 changes: 32 additions & 0 deletions
32
migrations/versions/a72f117515c5_add_description_created_time_and_.py
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,32 @@ | ||
"""Add description, created_time and updated_time columns to IndexRecord | ||
Revision ID: a72f117515c5 | ||
Revises: 15f2e9345ade | ||
Create Date: 2023-04-11 10:00:59.250768 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a72f117515c5" | ||
down_revision = "15f2e9345ade" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"index_record", sa.Column("content_created_date", sa.DateTime, nullable=True) | ||
) | ||
op.add_column( | ||
"index_record", sa.Column("content_updated_date", sa.DateTime, nullable=True) | ||
) | ||
op.add_column("index_record", sa.Column("description", sa.VARCHAR(), nullable=True)) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("index_record", "content_created_date") | ||
op.drop_column("index_record", "content_updated_date") | ||
op.drop_column("index_record", "description") |
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
48 changes: 48 additions & 0 deletions
48
tests/postgres/migrations/test_a72f117515c5_add_description_created_time_and_.py
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,48 @@ | ||
from alembic.config import main as alembic_main | ||
|
||
|
||
def test_upgrade(postgres_driver): | ||
conn = postgres_driver.engine.connect() | ||
alembic_main(["--raiseerr", "upgrade", "a72f117515c5"]) | ||
cols = conn.execute( | ||
"SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'index_record'" | ||
) | ||
expected_schema = [ | ||
("did", "character varying"), | ||
("baseid", "character varying"), | ||
("rev", "character varying"), | ||
("form", "character varying"), | ||
("size", "bigint"), | ||
("created_date", "timestamp without time zone"), | ||
("updated_date", "timestamp without time zone"), | ||
("file_name", "character varying"), | ||
("version", "character varying"), | ||
("uploader", "character varying"), | ||
("description", "character varying"), | ||
("content_created_date", "timestamp without time zone"), | ||
("content_updated_date", "timestamp without time zone"), | ||
] | ||
actual_schema = sorted([i for i in cols]) | ||
assert sorted(expected_schema) == actual_schema | ||
|
||
|
||
def test_downgrade(postgres_driver): | ||
conn = postgres_driver.engine.connect() | ||
alembic_main(["--raiseerr", "downgrade", "15f2e9345ade"]) | ||
cols = conn.execute( | ||
"SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'index_record'" | ||
) | ||
expected_schema = [ | ||
("did", "character varying"), | ||
("baseid", "character varying"), | ||
("rev", "character varying"), | ||
("form", "character varying"), | ||
("size", "bigint"), | ||
("created_date", "timestamp without time zone"), | ||
("updated_date", "timestamp without time zone"), | ||
("file_name", "character varying"), | ||
("version", "character varying"), | ||
("uploader", "character varying"), | ||
] | ||
actual_schema = sorted([i for i in cols]) | ||
assert sorted(expected_schema) == actual_schema |