Skip to content

Commit 1a80e3b

Browse files
committed
Models added and relationships
1 parent 0a2a676 commit 1a80e3b

16 files changed

Lines changed: 233 additions & 3 deletions
2.13 KB
Binary file not shown.

lib/debug.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python3
22

33
from sqlalchemy import create_engine
4-
5-
from models import Company, Dev
4+
from sqlalchemy.orm import sessionmaker
5+
from models import Company, Dev, Freebie
66

77
if __name__ == '__main__':
88
engine = create_engine('sqlite:///freebies.db')
9+
Session = sessionmaker(bind = engine)
10+
session = Session()
11+
912
import ipdb; ipdb.set_trace()

lib/freebies.db

16 KB
Binary file not shown.
1.81 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Editted models
2+
3+
Revision ID: 29f5c04539c3
4+
Revises: 9326f89afe90
5+
Create Date: 2023-12-27 14:12:26.039794
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '29f5c04539c3'
14+
down_revision = '9326f89afe90'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
pass
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade() -> None:
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
pass
28+
# ### end Alembic commands ###
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Freebies class table
2+
3+
Revision ID: 31785c9690e0
4+
Revises: 5f72c58bf48c
5+
Create Date: 2023-12-27 12:31:22.687794
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '31785c9690e0'
14+
down_revision = '5f72c58bf48c'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('freebies',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('item_name', sa.String(), nullable=True),
24+
sa.Column('value', sa.Integer(), nullable=True),
25+
sa.PrimaryKeyConstraint('id')
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade() -> None:
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_table('freebies')
33+
# ### end Alembic commands ###
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Tables relationships editted
2+
3+
Revision ID: 9326f89afe90
4+
Revises: 9cd8e4c0fac9
5+
Create Date: 2023-12-27 13:26:48.061328
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '9326f89afe90'
14+
down_revision = '9cd8e4c0fac9'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
pass
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade() -> None:
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
pass
28+
# ### end Alembic commands ###
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Tables relationships
2+
3+
Revision ID: 9cd8e4c0fac9
4+
Revises: 31785c9690e0
5+
Create Date: 2023-12-27 13:23:35.803194
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '9cd8e4c0fac9'
14+
down_revision = '31785c9690e0'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('company_dev',
22+
sa.Column('company_id', sa.Integer(), nullable=False),
23+
sa.Column('dev_id', sa.Integer(), nullable=False),
24+
sa.ForeignKeyConstraint(['company_id'], ['companies.id'], name=op.f('fk_company_dev_company_id_companies')),
25+
sa.ForeignKeyConstraint(['dev_id'], ['devs.id'], name=op.f('fk_company_dev_dev_id_devs')),
26+
sa.PrimaryKeyConstraint('company_id', 'dev_id')
27+
)
28+
with op.batch_alter_table('freebies', schema=None) as batch_op:
29+
batch_op.add_column(sa.Column('company_id', sa.Integer(), nullable=True))
30+
batch_op.add_column(sa.Column('dev_id', sa.Integer(), nullable=True))
31+
batch_op.create_foreign_key(batch_op.f('fk_freebies_dev_id_devs'), 'devs', ['dev_id'], ['id'])
32+
batch_op.create_foreign_key(batch_op.f('fk_freebies_company_id_companies'), 'companies', ['company_id'], ['id'])
33+
34+
# ### end Alembic commands ###
35+
36+
37+
def downgrade() -> None:
38+
# ### commands auto generated by Alembic - please adjust! ###
39+
with op.batch_alter_table('freebies', schema=None) as batch_op:
40+
batch_op.drop_constraint(batch_op.f('fk_freebies_company_id_companies'), type_='foreignkey')
41+
batch_op.drop_constraint(batch_op.f('fk_freebies_dev_id_devs'), type_='foreignkey')
42+
batch_op.drop_column('dev_id')
43+
batch_op.drop_column('company_id')
44+
45+
op.drop_table('company_dev')
46+
# ### end Alembic commands ###
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)