-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added created and last_modified columns to family documents. (#181)
- Loading branch information
1 parent
9221f3f
commit 80cd88e
Showing
10 changed files
with
343 additions
and
26 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 |
---|---|---|
|
@@ -190,3 +190,4 @@ backend/models | |
|
||
# PyCharm | ||
.idea/ | ||
alembic/replaceable_objects/** |
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
96 changes: 96 additions & 0 deletions
96
alembic/versions/0020_added_created_and_last_modified_columns_.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,96 @@ | ||
""" | ||
Added created and last modified columns on documents. | ||
Revision ID: 0020 | ||
Revises: 0019 | ||
Create Date: 2023-11-16 17:01:21.091516 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic_utils.pg_function import PGFunction | ||
from alembic_utils.pg_trigger import PGTrigger | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "0020" | ||
down_revision = "0019" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"family_document", | ||
sa.Column( | ||
"created", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
) | ||
op.add_column( | ||
"family_document", | ||
sa.Column("last_modified", sa.DateTime(timezone=True), nullable=False), | ||
) | ||
public_update_last_modified = PGFunction( | ||
schema="public", | ||
signature="update_last_modified()", | ||
definition=""" | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.last_modified = NOW(); | ||
RETURN NEW; | ||
END; | ||
$$ language 'plpgsql' | ||
""", | ||
) | ||
op.create_entity(public_update_last_modified) # type: ignore | ||
|
||
public_family_document_update_last_modified = PGTrigger( | ||
schema="public", | ||
signature="update_last_modified", | ||
on_entity="public.family_document", | ||
definition=""" | ||
BEFORE INSERT OR UPDATE ON public.family_document | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE public.update_last_modified() | ||
""", | ||
) | ||
op.create_entity(public_family_document_update_last_modified) # type: ignore | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
public_family_document_update_last_modified = PGTrigger( | ||
schema="public", | ||
signature="update_last_modified", | ||
on_entity="public.family_document", | ||
is_constraint=False, | ||
definition=""" | ||
BEFORE INSERT OR UPDATE ON public.family_document | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE public.update_last_modified() | ||
""", | ||
) | ||
op.drop_entity(public_family_document_update_last_modified) # type: ignore | ||
|
||
public_update_last_modified = PGFunction( | ||
schema="public", | ||
signature="update_last_modified()", | ||
definition=""" | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.last_modified = NOW(); | ||
RETURN NEW; | ||
END; | ||
$$ language 'plpgsql' | ||
""", | ||
) | ||
op.drop_entity(public_update_last_modified) # type: ignore | ||
|
||
op.drop_column("family_document", "last_modified") | ||
op.drop_column("family_document", "created") | ||
# ### end Alembic commands ### |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.