-
Notifications
You must be signed in to change notification settings - Fork 0
/
88948031a878_add_no_lic_regulation_check.py
103 lines (92 loc) · 2.67 KB
/
88948031a878_add_no_lic_regulation_check.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""add No LIC regulation check
Revision ID: 88948031a878
Revises: 91a93a56a303
Create Date: 2023-08-10 12:12:27.357582
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import Session
from app.models.regulation_check import UnitType, RegulationCheckType
# revision identifiers, used by Alembic.
revision = "88948031a878"
down_revision = "91a93a56a303"
branch_labels = None
depends_on = None
def fill_new_regulation_check():
session = Session(bind=op.get_bind())
session.execute(
sa.text(
"""
INSERT INTO regulation_check(
creation_time,
type,
label,
description,
date_application_start,
regulation_rule,
variables,
unit
)
VALUES
(
NOW(),
:type,
:label,
:description,
TIMESTAMP '2019-11-01',
:regulation_rule,
:variables,
:unit
)
"""
),
dict(
type=RegulationCheckType.NO_LIC,
label="Absence de livret individuel de contrôle à bord",
description="Défaut de documents nécessaires au décompte de la durée du travail (L. 3121-67 du Code du travail et R. 3312‑58 du Code des transports + arrêté du 20 juillet 1998)",
regulation_rule=None,
variables=None,
unit=UnitType.DAY,
),
)
def upgrade():
op.alter_column("regulation_check", "regulation_rule", nullable=True)
op.execute(
"ALTER TABLE regulation_check DROP CONSTRAINT IF EXISTS regulationchecktype"
)
op.alter_column(
"regulation_check",
"type",
type_=sa.Enum(
"minimumDailyRest",
"maximumWorkDayTime",
"minimumWorkDayBreak",
"maximumUninterruptedWorkTime",
"maximumWorkedDaysInWeek",
"noLic",
name="regulationchecktype",
native_enum=False,
),
nullable=False,
)
fill_new_regulation_check()
def downgrade():
op.execute("DELETE FROM regulation_check WHERE type = 'noLic'")
op.execute(
"ALTER TABLE regulation_check DROP CONSTRAINT IF EXISTS regulationchecktype"
)
op.alter_column(
"regulation_check",
"type",
type_=sa.Enum(
"minimumDailyRest",
"maximumWorkDayTime",
"minimumWorkDayBreak",
"maximumUninterruptedWorkTime",
"maximumWorkedDaysInWeek",
name="regulationchecktype",
native_enum=False,
),
nullable=False,
)
op.alter_column("regulation_check", "regulation_rule", nullable=False)