2023080523_create_first_application_load_76f559337a4a.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. """create_first_application_load
  2. Revision ID: 76f559337a4a
  3. Revises: 07c71f4389b6
  4. Create Date: 2023-08-05 21:23:21.563804
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = "76f559337a4a"
  10. down_revision = "07c71f4389b6"
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. # ### commands auto generated by Alembic - please adjust! ###
  15. op.create_table(
  16. "projects",
  17. sa.Column("id", sa.UUID(as_uuid=False), nullable=False),
  18. sa.Column(
  19. "created_at",
  20. sa.DateTime(timezone=True),
  21. server_default=sa.text("now()"),
  22. nullable=False,
  23. ),
  24. sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
  25. sa.Column("name", sa.String(length=128), nullable=False),
  26. sa.Column("is_public", sa.Boolean(), nullable=False),
  27. sa.PrimaryKeyConstraint("id"),
  28. )
  29. op.create_index(op.f("ix_projects_name"), "projects", ["name"], unique=True)
  30. op.create_table(
  31. "slots",
  32. sa.Column("id", sa.UUID(as_uuid=False), nullable=False),
  33. sa.Column("project_id", sa.UUID(as_uuid=False), nullable=False),
  34. sa.Column(
  35. "created_at",
  36. sa.DateTime(timezone=True),
  37. server_default=sa.text("now()"),
  38. nullable=False,
  39. ),
  40. sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
  41. sa.Column("title", sa.String(length=128), nullable=False),
  42. sa.Column("description", sa.String(), nullable=False),
  43. sa.Column("starting_time", sa.DateTime(timezone=True), nullable=False),
  44. sa.Column("ending_time", sa.DateTime(timezone=True), nullable=False),
  45. sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
  46. sa.PrimaryKeyConstraint("id"),
  47. )
  48. op.create_table(
  49. "volunteers",
  50. sa.Column("id", sa.UUID(as_uuid=False), nullable=False),
  51. sa.Column("project_id", sa.UUID(as_uuid=False), nullable=False),
  52. sa.Column(
  53. "created_at",
  54. sa.DateTime(timezone=True),
  55. server_default=sa.text("now()"),
  56. nullable=False,
  57. ),
  58. sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
  59. sa.Column("name", sa.String(length=128), nullable=False),
  60. sa.Column("surname", sa.String(length=128), nullable=False),
  61. sa.Column("email", sa.String(length=128), nullable=False),
  62. sa.Column("phone_number", sa.String(length=128), nullable=False),
  63. sa.Column("automatic_sms", sa.Boolean(), nullable=False),
  64. sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
  65. sa.PrimaryKeyConstraint("id"),
  66. )
  67. op.create_table(
  68. "association_volunteer_slot",
  69. sa.Column("volunteer_id", sa.UUID(as_uuid=False), nullable=False),
  70. sa.Column("slot_id", sa.UUID(as_uuid=False), nullable=False),
  71. sa.ForeignKeyConstraint(["slot_id"], ["slots.id"], ondelete="CASCADE"),
  72. sa.ForeignKeyConstraint(
  73. ["volunteer_id"], ["volunteers.id"], ondelete="CASCADE"
  74. ),
  75. sa.PrimaryKeyConstraint("volunteer_id", "slot_id"),
  76. )
  77. op.create_table(
  78. "sms",
  79. sa.Column("id", sa.UUID(as_uuid=False), nullable=False),
  80. sa.Column("project_id", sa.UUID(as_uuid=False), nullable=False),
  81. sa.Column("volunteer_id", sa.UUID(as_uuid=False), nullable=False),
  82. sa.Column(
  83. "created_at",
  84. sa.DateTime(timezone=True),
  85. server_default=sa.text("now()"),
  86. nullable=False,
  87. ),
  88. sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
  89. sa.Column("content", sa.String(), nullable=False),
  90. sa.Column("phone_number", sa.String(length=24), nullable=False),
  91. sa.Column("sending_time", sa.DateTime(timezone=True), nullable=False),
  92. sa.Column("send_time", sa.DateTime(timezone=True), nullable=False),
  93. sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
  94. sa.ForeignKeyConstraint(
  95. ["volunteer_id"],
  96. ["volunteers.id"],
  97. ),
  98. sa.PrimaryKeyConstraint("id"),
  99. )
  100. op.create_index(op.f("ix_sms_content"), "sms", ["content"], unique=True)
  101. # ### end Alembic commands ###
  102. def downgrade():
  103. # ### commands auto generated by Alembic - please adjust! ###
  104. op.drop_index(op.f("ix_sms_content"), table_name="sms")
  105. op.drop_table("sms")
  106. op.drop_table("association_volunteer_slot")
  107. op.drop_table("volunteers")
  108. op.drop_table("slots")
  109. op.drop_index(op.f("ix_projects_name"), table_name="projects")
  110. op.drop_table("projects")
  111. # ### end Alembic commands ###