aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py
blob: 718aa75ae97db813b9148978d1493420baff8cdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""sqlite_autoincrement

Revision ID: cb038f79982e
Revises: 2dcb0c0048dc
Create Date: 2020-04-13 17:40:02.426957

"""

# revision identifiers, used by Alembic.
revision = "cb038f79982e"
down_revision = "2dcb0c0048dc"

from alembic import op
import sqlalchemy as sa


def upgrade():
    bind = op.get_bind()
    if bind.engine.name == "sqlite":
        alter_table_batches = [
            op.batch_alter_table(
                "person", recreate="always", table_kwargs={"sqlite_autoincrement": True}
            ),
            op.batch_alter_table(
                "bill", recreate="always", table_kwargs={"sqlite_autoincrement": True}
            ),
            op.batch_alter_table(
                "billowers",
                recreate="always",
                table_kwargs={"sqlite_autoincrement": True},
            ),
        ]

        for batch_op in alter_table_batches:
            with batch_op:
                pass


def downgrade():
    bind = op.get_bind()
    if bind.engine.name == "sqlite":
        alter_table_batches = [
            op.batch_alter_table(
                "person",
                recreate="always",
                table_kwargs={"sqlite_autoincrement": False},
            ),
            op.batch_alter_table(
                "bill", recreate="always", table_kwargs={"sqlite_autoincrement": False}
            ),
            op.batch_alter_table(
                "billowers",
                recreate="always",
                table_kwargs={"sqlite_autoincrement": False},
            ),
        ]

        for batch_op in alter_table_batches:
            with batch_op:
                pass