Skip to content

Commit 26c406d

Browse files
committed
Introduce and populate user_id column in user_bookmarks
1 parent bc21002 commit 26c406d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Introduce and populate userid column in bookmarks table
2+
3+
Revision ID: 59709e421270
4+
Revises: 66d912f96db6
5+
Create Date: 2024-12-13 10:07:25.614981
6+
7+
"""
8+
import os
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
qwc_config_schema = os.getenv("QWC_CONFIG_SCHEMA", "qwc_config")
13+
14+
# revision identifiers, used by Alembic.
15+
revision = '59709e421270'
16+
down_revision = '66d912f96db6'
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
sql = sa.sql.text("""
23+
ALTER TABLE {schema}.user_bookmarks
24+
ADD COLUMN user_id integer;
25+
""".format(schema=qwc_config_schema))
26+
conn = op.get_bind()
27+
conn.execute(sql)
28+
29+
sql = sa.sql.text("""
30+
UPDATE {schema}.user_bookmarks
31+
SET user_id = users.id
32+
FROM {schema}.users
33+
WHERE user_bookmarks.username = users.name;
34+
""".format(schema=qwc_config_schema))
35+
conn = op.get_bind()
36+
conn.execute(sql)
37+
38+
39+
def downgrade():
40+
sql = sa.sql.text("""
41+
ALTER TABLE {schema}.user_bookmarks
42+
DROP COLUMN user_id;
43+
""".format(schema=qwc_config_schema))
44+
conn = op.get_bind()
45+
conn.execute(sql)

0 commit comments

Comments
 (0)