-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timezone info to timestamp columns
- Loading branch information
1 parent
58c7182
commit 25f3851
Showing
6 changed files
with
245 additions
and
3 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
154 changes: 154 additions & 0 deletions
154
...tructure/database/migrations/versions/2024_06_05_03_43-add_timezone_to_datetime_fields.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,154 @@ | ||
"""Add timezone to datetime fields | ||
Revision ID: 8095e19c1e8b | ||
Revises: f099d463803a | ||
Create Date: 2024-06-05 03:43:10.878950 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '8095e19c1e8b' | ||
down_revision = 'f099d463803a' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
# Tables with `created_at` and `updated_at` columns | ||
general_tables = [ | ||
'activities', | ||
'activity_events', | ||
'activity_histories', | ||
'activity_item_histories', | ||
'activity_items', | ||
'alerts', | ||
'answer_notes', | ||
'answers', | ||
'answers_items', | ||
'applet_histories', | ||
'applets', | ||
'cart', | ||
'events', | ||
'flow_events', | ||
'flow_histories', | ||
'flow_item_histories', | ||
'flow_items', | ||
'flows', | ||
'folder_applets', | ||
'folders', | ||
'invitations', | ||
'jobs', | ||
'library', | ||
'notification_logs', | ||
'notifications', | ||
'periodicity', | ||
'reminders', | ||
'reusable_item_choices', | ||
'subject_relations', | ||
'subjects', | ||
'themes', | ||
'token_blacklist', | ||
'transfer_ownership', | ||
'user_applet_accesses', | ||
'user_devices', | ||
'user_events', | ||
'user_pins', | ||
'users', | ||
'users_workspaces' | ||
] | ||
|
||
# Tables with other datetime columns | ||
specific_tables_and_columns = [ | ||
('applets', [('pinned_at', False)]), | ||
('token_blacklist', [('exp', False)]), | ||
('folder_applets', [('pinned_at', False)]), | ||
('users', [('last_seen_at', False)]), | ||
] | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
for table_name in general_tables: | ||
op.alter_column( | ||
table_name, | ||
'created_at', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'updated_at', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_date', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_updated', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True | ||
) | ||
|
||
for table_name, column_names_and_nullability in specific_tables_and_columns: | ||
for column_name, nullable in column_names_and_nullability: | ||
op.alter_column( | ||
table_name, | ||
column_name, | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=nullable | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
for table_name in general_tables: | ||
op.alter_column( | ||
table_name, | ||
'created_at', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'updated_at', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_date', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=True | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_updated', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=True | ||
) | ||
|
||
for table_name, column_names_and_nullability in specific_tables_and_columns: | ||
for column_name, nullable in column_names_and_nullability: | ||
op.alter_column( | ||
table_name, | ||
column_name, | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=nullable | ||
) | ||
# ### end Alembic commands ### |
Empty file.
86 changes: 86 additions & 0 deletions
86
...atabase/migrations_arbitrary/versions/2024_06_05_03_43-add_timezone_to_datetime_fields.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,86 @@ | ||
"""Add timezone to datetime fields in arbitrary database | ||
Revision ID: 8095e19c1e8b | ||
Revises: f099d463803a | ||
Create Date: 2024-06-05 03:43:10.878950 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '8095e19c1e8b' | ||
down_revision = '267dd5b56abf' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
# Tables with `created_at` and `updated_at` columns | ||
general_tables = ['answers', 'answers_items'] | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
for table_name in general_tables: | ||
op.alter_column( | ||
table_name, | ||
'created_at', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'updated_at', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_date', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_updated', | ||
existing_type=sa.DateTime(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
for table_name in general_tables: | ||
op.alter_column( | ||
table_name, | ||
'created_at', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'updated_at', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=False | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_date', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=True | ||
) | ||
op.alter_column( | ||
table_name, | ||
'migrated_updated', | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=sa.DateTime(), | ||
existing_nullable=True | ||
) | ||
# ### end Alembic commands ### |
Empty file.