-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the 'Add to macros' feature and fixed various usabi…
…lity issues. #4735
- Loading branch information
1 parent
36a71dc
commit 4e3ec91
Showing
14 changed files
with
279 additions
and
51 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
"""empty message | ||
Revision ID: ac2c2e27dc2d | ||
Revises: ec0f11f9a4e6 | ||
Create Date: 2024-05-17 19:35:03.700104 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'ac2c2e27dc2d' | ||
down_revision = 'ec0f11f9a4e6' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
meta = sa.MetaData() | ||
meta.reflect(op.get_bind(), only=('user_macros',)) | ||
user_macros_table = sa.Table('user_macros', meta) | ||
|
||
# Create a select statement | ||
stmt = sa.select( | ||
user_macros_table.columns.mid, | ||
user_macros_table.columns.uid, user_macros_table.columns.name, | ||
user_macros_table.columns.sql | ||
) | ||
# Fetch the data from the user_macros table | ||
results = op.get_bind().execute(stmt).fetchall() | ||
|
||
# Drop and re-create user macro table. | ||
op.drop_table('user_macros') | ||
op.create_table( | ||
'user_macros', | ||
sa.Column('id', sa.Integer(), autoincrement=True), | ||
sa.Column('mid', sa.Integer(), nullable=True), | ||
sa.Column('uid', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.String(length=1024), nullable=False), | ||
sa.Column('sql', sa.String()), | ||
sa.ForeignKeyConstraint(['mid'], ['macros.id'], ondelete='CASCADE'), | ||
sa.ForeignKeyConstraint(['uid'], ['user.id'], ondelete='CASCADE'), | ||
sa.PrimaryKeyConstraint('id',)) | ||
|
||
# Reflect the new table structure | ||
meta.reflect(op.get_bind(), only=('user_macros',)) | ||
new_user_macros_table = sa.Table('user_macros', meta) | ||
|
||
# Bulk insert the fetched data into the new user_macros table | ||
op.bulk_insert( | ||
new_user_macros_table, | ||
[ | ||
{'mid': row[0], 'uid': row[1], 'name': row[2], 'sql': row[3]} | ||
for row in results | ||
] | ||
) | ||
|
||
def downgrade(): | ||
# pgAdmin only upgrades, downgrade not implemented. | ||
pass |
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
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
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
Oops, something went wrong.