1- """init migrate
1+ """empty message
22
3- Revision ID: 7bc0658e9c3d
3+ Revision ID: 9255441d2a22
44Revises:
5- Create Date: 2025-03-23 13:21:15.057776
5+ Create Date: 2025-03-28 14:45:25.748190
66
77"""
88from alembic import op
99import sqlalchemy as sa
1010
1111
1212# revision identifiers, used by Alembic.
13- revision = '7bc0658e9c3d '
13+ revision = '9255441d2a22 '
1414down_revision = None
1515branch_labels = None
1616depends_on = None
@@ -34,6 +34,22 @@ def upgrade():
3434 with op .batch_alter_table ('client' , schema = None ) as batch_op :
3535 batch_op .create_index (batch_op .f ('ix_client_email' ), ['email' ], unique = False )
3636
37+ op .create_table ('establishment' ,
38+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
39+ sa .Column ('official_name' , sa .String (length = 40 ), nullable = False ),
40+ sa .Column ('fantasy_name' , sa .String (length = 40 ), nullable = False ),
41+ sa .Column ('cnpj' , sa .String (length = 14 ), nullable = False ),
42+ sa .Column ('telephone' , sa .String (length = 11 ), nullable = False ),
43+ sa .Column ('zip_code' , sa .String (length = 9 ), nullable = False ),
44+ sa .Column ('state' , sa .String (length = 19 ), nullable = False ),
45+ sa .Column ('city' , sa .String (length = 30 ), nullable = False ),
46+ sa .Column ('address' , sa .String (length = 120 ), nullable = False ),
47+ sa .Column ('complement' , sa .String (length = 120 ), nullable = True ),
48+ sa .PrimaryKeyConstraint ('id' ),
49+ sa .UniqueConstraint ('cnpj' ),
50+ sa .UniqueConstraint ('fantasy_name' ),
51+ sa .UniqueConstraint ('official_name' )
52+ )
3753 op .create_table ('lead' ,
3854 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
3955 sa .Column ('created_at' , sa .DateTime (), nullable = True ),
@@ -43,19 +59,6 @@ def upgrade():
4359 with op .batch_alter_table ('lead' , schema = None ) as batch_op :
4460 batch_op .create_index (batch_op .f ('ix_lead_email' ), ['email' ], unique = True )
4561
46- op .create_table ('restaurant' ,
47- sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
48- sa .Column ('name' , sa .String (length = 40 ), nullable = False ),
49- sa .Column ('description' , sa .String (length = 120 ), nullable = False ),
50- sa .Column ('classification' , sa .Float (precision = 3 ), nullable = False ),
51- sa .Column ('location' , sa .String (length = 120 ), nullable = False ),
52- sa .Column ('url_image_logo' , sa .String (length = 800 ), nullable = True ),
53- sa .Column ('url_image_banner' , sa .String (length = 800 ), nullable = True ),
54- sa .Column ('telephone' , sa .String (length = 11 ), nullable = False ),
55- sa .Column ('has_plastic' , sa .Boolean (), nullable = False ),
56- sa .PrimaryKeyConstraint ('id' ),
57- sa .UniqueConstraint ('name' )
58- )
5962 op .create_table ('user' ,
6063 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
6164 sa .Column ('firstname' , sa .String (length = 20 ), nullable = False ),
@@ -68,11 +71,11 @@ def upgrade():
6871 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
6972 sa .Column ('created_at' , sa .DateTime (), nullable = True ),
7073 sa .Column ('client_id' , sa .Integer (), nullable = True ),
71- sa .Column ('restaurant_id ' , sa .Integer (), nullable = True ),
74+ sa .Column ('establishment_id ' , sa .Integer (), nullable = True ),
7275 sa .Column ('total_value' , sa .Float (), nullable = True ),
7376 sa .Column ('status' , sa .Enum ('pre_order' , 'confirmed' , 'doing' , 'done' , 'canceled' , name = 'order_status' ), nullable = True ),
7477 sa .ForeignKeyConstraint (['client_id' ], ['client.id' ], ),
75- sa .ForeignKeyConstraint (['restaurant_id ' ], ['restaurant .id' ], ),
78+ sa .ForeignKeyConstraint (['establishment_id ' ], ['establishment .id' ], ),
7679 sa .PrimaryKeyConstraint ('id' )
7780 )
7881 op .create_table ('product' ,
@@ -86,8 +89,8 @@ def upgrade():
8689 sa .Column ('has_lactose' , sa .Boolean (), nullable = False ),
8790 sa .Column ('is_vegan' , sa .Boolean (), nullable = False ),
8891 sa .Column ('is_vegetarian' , sa .Boolean (), nullable = False ),
89- sa .Column ('restaurant_id ' , sa .Integer (), nullable = False ),
90- sa .ForeignKeyConstraint (['restaurant_id ' ], ['restaurant .id' ], ),
92+ sa .Column ('establishment_id ' , sa .Integer (), nullable = False ),
93+ sa .ForeignKeyConstraint (['establishment_id ' ], ['establishment .id' ], ),
9194 sa .PrimaryKeyConstraint ('id' )
9295 )
9396 op .create_table ('order_product_association' ,
@@ -111,28 +114,29 @@ def upgrade():
111114 sa .ForeignKeyConstraint (['order_id' ], ['order.id' ], ),
112115 sa .PrimaryKeyConstraint ('id' )
113116 )
114- op .create_table ('products_restaurants' ,
115- sa .Column ('product_id' , sa .Integer (), nullable = True ),
116- sa .Column ('restaurant_id' , sa .Integer (), nullable = True ),
117+ op .create_table ('products_establishment' ,
118+ sa .Column ('product_id' , sa .Integer (), nullable = False ),
119+ sa .Column ('establishment_id' , sa .Integer (), nullable = False ),
120+ sa .ForeignKeyConstraint (['establishment_id' ], ['establishment.id' ], ),
117121 sa .ForeignKeyConstraint (['product_id' ], ['product.id' ], ),
118- sa .ForeignKeyConstraint ([ 'restaurant_id' ], [ 'restaurant.id' ], )
122+ sa .PrimaryKeyConstraint ( 'product_id' , 'establishment_id' )
119123 )
120124 # ### end Alembic commands ###
121125
122126
123127def downgrade ():
124128 # ### commands auto generated by Alembic - please adjust! ###
125- op .drop_table ('products_restaurants ' )
129+ op .drop_table ('products_establishment ' )
126130 op .drop_table ('payment' )
127131 op .drop_table ('order_product_association' )
128132 op .drop_table ('product' )
129133 op .drop_table ('order' )
130134 op .drop_table ('user' )
131- op .drop_table ('restaurant' )
132135 with op .batch_alter_table ('lead' , schema = None ) as batch_op :
133136 batch_op .drop_index (batch_op .f ('ix_lead_email' ))
134137
135138 op .drop_table ('lead' )
139+ op .drop_table ('establishment' )
136140 with op .batch_alter_table ('client' , schema = None ) as batch_op :
137141 batch_op .drop_index (batch_op .f ('ix_client_email' ))
138142
0 commit comments