-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce and populate user_id column in user_bookmarks
- Loading branch information
1 parent
bc21002
commit 26c406d
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
alembic/versions/59709e421270_introduce_and_populate_userid_column_in_.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,45 @@ | ||
"""Introduce and populate userid column in bookmarks table | ||
Revision ID: 59709e421270 | ||
Revises: 66d912f96db6 | ||
Create Date: 2024-12-13 10:07:25.614981 | ||
""" | ||
import os | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
qwc_config_schema = os.getenv("QWC_CONFIG_SCHEMA", "qwc_config") | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '59709e421270' | ||
down_revision = '66d912f96db6' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
sql = sa.sql.text(""" | ||
ALTER TABLE {schema}.user_bookmarks | ||
ADD COLUMN user_id integer; | ||
""".format(schema=qwc_config_schema)) | ||
conn = op.get_bind() | ||
conn.execute(sql) | ||
|
||
sql = sa.sql.text(""" | ||
UPDATE {schema}.user_bookmarks | ||
SET user_id = users.id | ||
FROM {schema}.users | ||
WHERE user_bookmarks.username = users.name; | ||
""".format(schema=qwc_config_schema)) | ||
conn = op.get_bind() | ||
conn.execute(sql) | ||
|
||
|
||
def downgrade(): | ||
sql = sa.sql.text(""" | ||
ALTER TABLE {schema}.user_bookmarks | ||
DROP COLUMN user_id; | ||
""".format(schema=qwc_config_schema)) | ||
conn = op.get_bind() | ||
conn.execute(sql) |