1
0

c34f4b09ef18_star_a_project.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """star_a_project
  2. Revision ID: c34f4b09ef18
  3. Revises: 8a5d68f74beb
  4. Create Date: 2017-07-07 00:08:18.257075
  5. """
  6. # revision identifiers, used by Alembic.
  7. revision = 'c34f4b09ef18'
  8. down_revision = '8a5d68f74beb'
  9. from alembic import op
  10. import sqlalchemy as sa
  11. def upgrade():
  12. ''' Add a new table to store data about who starred which project '''
  13. op.create_table(
  14. 'stargazers',
  15. sa.Column('id', sa.Integer, primary_key=True),
  16. sa.Column(
  17. 'project_id',
  18. sa.Integer,
  19. sa.ForeignKey(
  20. 'projects.id', onupdate='CASCADE', ondelete='CASCADE'),
  21. nullable=False,
  22. index=True,
  23. ),
  24. sa.Column(
  25. 'user_id',
  26. sa.Integer,
  27. sa.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'),
  28. nullable=False,
  29. )
  30. )
  31. op.create_unique_constraint(
  32. constraint_name='uq_stargazers_project_id_user_id_key',
  33. table_name='stargazers',
  34. columns=['project_id', 'user_id']
  35. )
  36. def downgrade():
  37. ''' Remove the stargazers table from the database '''
  38. op.drop_constraint(
  39. constraint_name='uq_stargazers_project_id_user_id_key',
  40. table_name='stargazers'
  41. )
  42. op.drop_table('stargazers')