Skip to content

Commit 0d33f25

Browse files
jmaPascalRepond
authored andcommitted
migration: create the database migration alembic file
Co-Authored-by: Johnny Mariéthoz <[email protected]>
1 parent ad928d2 commit 0d33f25

File tree

2 files changed

+116
-21
lines changed

2 files changed

+116
-21
lines changed

poetry.lock

Lines changed: 22 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# RERO ILS
4+
# Copyright (C) 2024 RERO
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as published by
8+
# the Free Software Foundation, version 3 of the License.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
"""Remove invoices and update the api harvester tables."""
19+
20+
import sqlalchemy as sa
21+
from alembic import op
22+
from sqlalchemy.dialects import postgresql
23+
24+
# revision identifiers, used by Alembic.
25+
revision = "c69ea6572971"
26+
down_revision = "8d97be2c8ad6"
27+
branch_labels = ()
28+
depends_on = None
29+
30+
31+
def upgrade():
32+
"""Upgrade database."""
33+
op.drop_table("acq_invoice_id")
34+
op.drop_table("acq_invoice_metadata")
35+
op.add_column(
36+
"apiharvester_config",
37+
sa.Column("classname", sa.String(length=255), nullable=False),
38+
)
39+
op.add_column("apiharvester_config", sa.Column("code", sa.Text(), nullable=True))
40+
op.drop_column("apiharvester_config", "comment")
41+
op.drop_column("apiharvester_config", "mimetype")
42+
op.drop_column("apiharvester_config", "size")
43+
op.drop_index("ix_uq_partial_files_object_is_head", table_name="files_object")
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade():
48+
"""Downgrade database."""
49+
op.create_index(
50+
"ix_uq_partial_files_object_is_head",
51+
"files_object",
52+
["bucket_id", "key"],
53+
unique=False,
54+
)
55+
op.add_column(
56+
"apiharvester_config",
57+
sa.Column("size", sa.INTEGER(), autoincrement=False, nullable=False),
58+
)
59+
op.add_column(
60+
"apiharvester_config",
61+
sa.Column(
62+
"mimetype", sa.VARCHAR(length=255), autoincrement=False, nullable=False
63+
),
64+
)
65+
op.add_column(
66+
"apiharvester_config",
67+
sa.Column("comment", sa.TEXT(), autoincrement=False, nullable=True),
68+
)
69+
op.drop_column("apiharvester_config", "code")
70+
op.drop_column("apiharvester_config", "classname")
71+
op.create_table(
72+
"acq_invoice_metadata",
73+
sa.Column(
74+
"created", postgresql.TIMESTAMP(), autoincrement=False, nullable=False
75+
),
76+
sa.Column(
77+
"updated", postgresql.TIMESTAMP(), autoincrement=False, nullable=False
78+
),
79+
sa.Column("id", postgresql.UUID(), autoincrement=False, nullable=False),
80+
sa.Column(
81+
"json",
82+
postgresql.JSONB(astext_type=sa.Text()),
83+
autoincrement=False,
84+
nullable=True,
85+
),
86+
sa.Column("version_id", sa.INTEGER(), autoincrement=False, nullable=False),
87+
sa.PrimaryKeyConstraint("id", name="pk_acq_invoice_metadata"),
88+
)
89+
op.create_table(
90+
"acq_invoice_id",
91+
sa.Column("recid", sa.BIGINT(), autoincrement=True, nullable=False),
92+
sa.PrimaryKeyConstraint("recid", name="pk_acq_invoice_id"),
93+
)
94+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)