@@ -51,25 +51,29 @@ def upgrade():
5151 """ ))
5252
5353 op .create_table ('booking_workday' ,
54- sa .Column ('contract_id' , sa .Integer (), nullable = True ),
55- sa .Column ('booking_id' , sa .String (), nullable = True ),
56- sa .Column ('name' , sa .Enum ('MONDAY' , 'TUESDAY' , 'WEDNESDAY' , 'THURSDAY' , 'FRIDAY' , 'SATURDAY' , 'SUNDAY' , name = 'bookingworkdayenum' ), nullable = False ),
57- sa .Column ('date' , sa .Date (), nullable = True ),
58- sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
59- sa .Column ('created_at' , sa .DateTime (), nullable = False ),
60- sa .Column ('updated_at' , sa .DateTime (), nullable = True ),
61- sa .ForeignKeyConstraint (['booking_id' ], ['booking.booking_id' ], ),
62- sa .ForeignKeyConstraint (['contract_id' ], ['booking_contract.id' ], ),
63- sa .PrimaryKeyConstraint ('id' )
54+ sa .Column ('contract_id' , sa .Integer (), nullable = True ),
55+ sa .Column ('booking_id' , sa .String (), nullable = True ),
56+ sa .Column ('name' , sa .Enum ('MONDAY' , 'TUESDAY' , 'WEDNESDAY' , 'THURSDAY' , 'FRIDAY' , 'SATURDAY' , 'SUNDAY' , name = 'bookingworkdayenum' ), nullable = False ),
57+ sa .Column ('date' , sa .Date (), nullable = True ),
58+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
59+ sa .Column ('created_at' , sa .DateTime (), nullable = False ),
60+ sa .Column ('updated_at' , sa .DateTime (), nullable = True ),
61+ sa .ForeignKeyConstraint (['booking_id' ], ['booking.booking_id' ], ),
62+ sa .ForeignKeyConstraint (['contract_id' ], ['booking_contract.id' ], ),
63+ sa .PrimaryKeyConstraint ('id' )
6464 )
65- op .create_table ('booking_clock_event' ,
66- sa .Column ('working_day_id' , sa .Integer (), nullable = False ),
67- sa .Column ('event_type' , sa .Enum ('CLOCK_IN' , 'CLOCK_OUT' , name = 'bookingclockeventtypeenum' ), nullable = False ),
68- sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
69- sa .Column ('created_at' , sa .DateTime (), nullable = False ),
70- sa .Column ('updated_at' , sa .DateTime (), nullable = True ),
71- sa .ForeignKeyConstraint (['working_day_id' ], ['booking_workday.id' ], ),
72- sa .PrimaryKeyConstraint ('id' )
65+ op .create_table ('booking_work_session' ,
66+ sa .Column ('working_day_id' , sa .Integer (), nullable = False ),
67+ sa .Column ('clock_in' , sa .DateTime (), nullable = True ),
68+ sa .Column ('clock_out' , sa .DateTime (), nullable = True ),
69+ sa .Column ('booking_id' , sa .String (), nullable = False ),
70+ # sa.Column('event_type', sa.Enum('CLOCK_IN', 'CLOCK_OUT', name='bookingclockeventtypeenum'), nullable=False),
71+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
72+ sa .Column ('created_at' , sa .DateTime (), nullable = False ),
73+ sa .Column ('updated_at' , sa .DateTime (), nullable = True ),
74+ sa .ForeignKeyConstraint (['working_day_id' ], ['booking_workday.id' ], ),
75+ sa .ForeignKeyConstraint (['booking_id' ], ['booking.booking_id' ], ),
76+ sa .PrimaryKeyConstraint ('id' )
7377 )
7478
7579 with op .batch_alter_table ('wallet' , schema = None ) as batch_op :
@@ -80,6 +84,28 @@ def upgrade():
8084 )
8185 )
8286
87+ with op .batch_alter_table ('booking' , schema = None ) as batch_op :
88+ batch_op .add_column (
89+ sa .Column (
90+ 'clock_in_flag' , sa .Boolean (),
91+ nullable = True , server_default = 'false'
92+ )
93+ )
94+ batch_op .add_column (
95+ sa .Column (
96+ 'current_work_session_id' ,
97+ sa .Integer (),
98+ nullable = True
99+ )
100+ )
101+ op .execute (
102+ """
103+ ALTER TABLE booking
104+ ADD CONSTRAINT fk_current_work_session_id
105+ FOREIGN KEY (current_work_session_id)
106+ REFERENCES booking_work_session (id);
107+ """
108+ )
83109 # ### end Alembic commands ###
84110
85111
@@ -99,14 +125,20 @@ def downgrade():
99125 SET status = CASE
100126 WHEN status::text = 'IN_PROGRESS' THEN '{ old_enum_values [0 ]} '::{ old_enum_name }
101127 WHEN status::text = 'COMPLETED' THEN '{ old_enum_values [1 ]} '::{ old_enum_name }
128+ WHEN status::text = 'PENDING' THEN NULL
102129 ELSE status
103130 END
104131 """ ))
105132
106133 with op .batch_alter_table ('wallet' , schema = None ) as batch_op :
107134 batch_op .drop_column ('is_activated' )
108- op .drop_table ('booking_clock_event' )
135+
136+ with op .batch_alter_table ('booking' , schema = None ) as batch_op :
137+ batch_op .drop_column ('clock_in_flag' )
138+ batch_op .drop_constraint ('fk_current_work_session_id' )
139+ batch_op .drop_column ('current_work_session_id' )
140+
141+ op .drop_table ('booking_work_session' )
109142 op .drop_table ('booking_workday' )
110143 op .execute ("DROP TYPE bookingworkdayenum" )
111- op .execute ("DROP TYPE bookingclockeventtypeenum" )
112144 # ### end Alembic commands ###
0 commit comments