5d39829d91af_create_data_sources_table.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """create_data_sources_table
  2. Revision ID: 5d39829d91af
  3. Revises: b087ce8b529f
  4. Create Date: 2018-07-09 17:17:36.276000
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = "5d39829d91af"
  10. down_revision = "b087ce8b529f"
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. # ### commands auto generated by Alembic - please adjust! ###
  15. op.create_table(
  16. "data_sources",
  17. sa.Column("id", sa.Integer(), nullable=False),
  18. sa.Column("label", sa.String(length=80), nullable=True),
  19. sa.Column("type", sa.String(length=80), nullable=True),
  20. sa.Column("source_id", sa.Integer(), nullable=True),
  21. sa.ForeignKeyConstraint(["source_id"], ["bvp_users.id"]),
  22. sa.PrimaryKeyConstraint("id"),
  23. )
  24. op.add_column("power", sa.Column("data_source", sa.Integer(), nullable=False))
  25. op.create_foreign_key(None, "power", "data_sources", ["data_source"], ["id"])
  26. op.add_column("price", sa.Column("data_source", sa.Integer(), nullable=False))
  27. op.create_foreign_key(None, "price", "data_sources", ["data_source"], ["id"])
  28. op.add_column("weather", sa.Column("data_source", sa.Integer(), nullable=False))
  29. op.create_foreign_key(None, "weather", "data_sources", ["data_source"], ["id"])
  30. # ### end Alembic commands ###
  31. def downgrade():
  32. # ### commands auto generated by Alembic - please adjust! ###
  33. op.drop_constraint(None, "weather", type_="foreignkey")
  34. op.drop_column("weather", "data_source")
  35. op.drop_constraint(None, "price", type_="foreignkey")
  36. op.drop_column("price", "data_source")
  37. op.drop_constraint(None, "power", type_="foreignkey")
  38. op.drop_column("power", "data_source")
  39. op.drop_table("data_sources")
  40. # ### end Alembic commands ###