[alembic] just one revision
Some checks failed
Python Quality & Tests / Lint, Typecheck, and Test (push) Failing after 31s
Some checks failed
Python Quality & Tests / Lint, Typecheck, and Test (push) Failing after 31s
This commit is contained in:
parent
8fe597ce70
commit
0318793cae
6 changed files with 255 additions and 424 deletions
|
|
@ -1,266 +0,0 @@
|
||||||
"""
|
|
||||||
|
|
||||||
Revision ID: 4e8d78ff6e9e
|
|
||||||
Revises: 97d77db27867
|
|
||||||
Create Date: 2026-04-07 14:41:20.398451
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "4e8d78ff6e9e"
|
|
||||||
down_revision: Union[str, Sequence[str], None] = "97d77db27867"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
_now = sa.text("CURRENT_TIMESTAMP")
|
|
||||||
_zero_int = sa.text("0")
|
|
||||||
_zero_float = sa.text("0")
|
|
||||||
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table(
|
|
||||||
"userproductusage",
|
|
||||||
sa.Column("product_id", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("count", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("id", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
|
||||||
sa.ForeignKeyConstraint(
|
|
||||||
["product_id"],
|
|
||||||
["product.id"],
|
|
||||||
),
|
|
||||||
sa.ForeignKeyConstraint(
|
|
||||||
["user_id"],
|
|
||||||
["user.id"],
|
|
||||||
),
|
|
||||||
sa.PrimaryKeyConstraint("id"),
|
|
||||||
sa.UniqueConstraint("user_id", "product_id"),
|
|
||||||
)
|
|
||||||
op.create_table(
|
|
||||||
"usersettings",
|
|
||||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("protein_goal", sa.Float(), nullable=False),
|
|
||||||
sa.Column("carb_goal", sa.Float(), nullable=False),
|
|
||||||
sa.Column("fat_goal", sa.Float(), nullable=False),
|
|
||||||
sa.Column("fiber_goal", sa.Float(), nullable=False),
|
|
||||||
sa.Column("calories_goal", sa.Float(), nullable=False),
|
|
||||||
sa.Column("id", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False),
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
|
||||||
sa.ForeignKeyConstraint(
|
|
||||||
["user_id"],
|
|
||||||
["user.id"],
|
|
||||||
),
|
|
||||||
sa.PrimaryKeyConstraint("id"),
|
|
||||||
sa.UniqueConstraint("user_id"),
|
|
||||||
)
|
|
||||||
# Create default settings for all existing users
|
|
||||||
op.execute(
|
|
||||||
sa.text(
|
|
||||||
"INSERT INTO usersettings"
|
|
||||||
" (user_id, protein_goal, carb_goal, fat_goal, fiber_goal, calories_goal,"
|
|
||||||
" version, created_at, last_changed)"
|
|
||||||
" SELECT id, 0, 0, 0, 0, 0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP"
|
|
||||||
' FROM "user"'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
op.drop_table("refreshtoken")
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column(
|
|
||||||
"protein_goal", sa.Float(), nullable=False, server_default=_zero_float
|
|
||||||
),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("carb_goal", sa.Float(), nullable=False, server_default=_zero_float),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("fat_goal", sa.Float(), nullable=False, server_default=_zero_float),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("fiber_goal", sa.Float(), nullable=False, server_default=_zero_float),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column(
|
|
||||||
"calories_goal", sa.Float(), nullable=False, server_default=_zero_float
|
|
||||||
),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"diary",
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.create_unique_constraint(None, "diary", ["user_id", "date"])
|
|
||||||
op.add_column(
|
|
||||||
"entry",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"entry",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"meal",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"meal",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"meal",
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"preset",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"preset",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"preset",
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"presetentry",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"presetentry",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column("calories", sa.Float(), nullable=False, server_default=_zero_float),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column("product", sa.Column("deleted_at", sa.DateTime(), nullable=True))
|
|
||||||
op.create_index(
|
|
||||||
"ix_product_barcode",
|
|
||||||
"product",
|
|
||||||
["barcode"],
|
|
||||||
unique=True,
|
|
||||||
postgresql_where=sa.text("deleted_at IS NULL"),
|
|
||||||
sqlite_where=sa.text("deleted_at IS NULL"),
|
|
||||||
)
|
|
||||||
op.drop_column("product", "hard_coded_calories")
|
|
||||||
op.drop_column("product", "usage_count_cached")
|
|
||||||
op.add_column(
|
|
||||||
"user",
|
|
||||||
sa.Column("version", sa.Integer(), nullable=False, server_default=_zero_int),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"user",
|
|
||||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"user",
|
|
||||||
sa.Column("last_changed", sa.DateTime(), nullable=False, server_default=_now),
|
|
||||||
)
|
|
||||||
op.add_column("user", sa.Column("deleted_at", sa.DateTime(), nullable=True))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column("user", "deleted_at")
|
|
||||||
op.drop_column("user", "last_changed")
|
|
||||||
op.drop_column("user", "created_at")
|
|
||||||
op.drop_column("user", "version")
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column(
|
|
||||||
"usage_count_cached",
|
|
||||||
sa.BIGINT(),
|
|
||||||
autoincrement=False,
|
|
||||||
nullable=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
op.add_column(
|
|
||||||
"product",
|
|
||||||
sa.Column(
|
|
||||||
"hard_coded_calories",
|
|
||||||
sa.DOUBLE_PRECISION(precision=53),
|
|
||||||
autoincrement=False,
|
|
||||||
nullable=True,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
op.drop_index(
|
|
||||||
"ix_product_barcode",
|
|
||||||
table_name="product",
|
|
||||||
postgresql_where=sa.text("deleted_at IS NULL"),
|
|
||||||
sqlite_where=sa.text("deleted_at IS NULL"),
|
|
||||||
)
|
|
||||||
op.drop_column("product", "deleted_at")
|
|
||||||
op.drop_column("product", "last_changed")
|
|
||||||
op.drop_column("product", "created_at")
|
|
||||||
op.drop_column("product", "version")
|
|
||||||
op.drop_column("product", "calories")
|
|
||||||
op.drop_column("presetentry", "created_at")
|
|
||||||
op.drop_column("presetentry", "version")
|
|
||||||
op.drop_column("preset", "last_changed")
|
|
||||||
op.drop_column("preset", "created_at")
|
|
||||||
op.drop_column("preset", "version")
|
|
||||||
op.drop_column("meal", "last_changed")
|
|
||||||
op.drop_column("meal", "created_at")
|
|
||||||
op.drop_column("meal", "version")
|
|
||||||
op.drop_column("entry", "created_at")
|
|
||||||
op.drop_column("entry", "version")
|
|
||||||
op.drop_constraint(None, "diary", type_="unique")
|
|
||||||
op.drop_column("diary", "last_changed")
|
|
||||||
op.drop_column("diary", "created_at")
|
|
||||||
op.drop_column("diary", "version")
|
|
||||||
op.drop_column("diary", "calories_goal")
|
|
||||||
op.drop_column("diary", "fiber_goal")
|
|
||||||
op.drop_column("diary", "fat_goal")
|
|
||||||
op.drop_column("diary", "carb_goal")
|
|
||||||
op.drop_column("diary", "protein_goal")
|
|
||||||
op.create_table(
|
|
||||||
"refreshtoken",
|
|
||||||
sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=False),
|
|
||||||
sa.Column("token", sa.VARCHAR(), autoincrement=False, nullable=False),
|
|
||||||
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
|
|
||||||
sa.ForeignKeyConstraint(
|
|
||||||
["user_id"], ["user.id"], name=op.f("refreshtoken_user_id_fkey")
|
|
||||||
),
|
|
||||||
sa.PrimaryKeyConstraint("id", name=op.f("refreshtoken_pkey")),
|
|
||||||
)
|
|
||||||
op.drop_table("usersettings")
|
|
||||||
op.drop_table("userproductusage")
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
"""
|
|
||||||
|
|
||||||
Revision ID: 564e5948f3ed
|
|
||||||
Revises: 4e8d78ff6e9e
|
|
||||||
Create Date: 2026-04-07 19:31:01.616100
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "564e5948f3ed"
|
|
||||||
down_revision: Union[str, Sequence[str], None] = "4e8d78ff6e9e"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_index(op.f("ix_entry_meal_id"), "entry", ["meal_id"], unique=False)
|
|
||||||
op.create_index(op.f("ix_entry_product_id"), "entry", ["product_id"], unique=False)
|
|
||||||
op.drop_column("entry", "processed")
|
|
||||||
op.create_index(op.f("ix_meal_diary_id"), "meal", ["diary_id"], unique=False)
|
|
||||||
op.create_index(op.f("ix_preset_user_id"), "preset", ["user_id"], unique=False)
|
|
||||||
op.create_index(
|
|
||||||
op.f("ix_presetentry_preset_id"),
|
|
||||||
"presetentry",
|
|
||||||
["preset_id"],
|
|
||||||
unique=False,
|
|
||||||
)
|
|
||||||
op.create_index(
|
|
||||||
op.f("ix_presetentry_product_id"),
|
|
||||||
"presetentry",
|
|
||||||
["product_id"],
|
|
||||||
unique=False,
|
|
||||||
)
|
|
||||||
op.create_index(
|
|
||||||
"ix_userproductusage_product_user",
|
|
||||||
"userproductusage",
|
|
||||||
["product_id", "user_id"],
|
|
||||||
unique=False,
|
|
||||||
)
|
|
||||||
op.create_index(
|
|
||||||
op.f("ix_userproductusage_user_id"),
|
|
||||||
"userproductusage",
|
|
||||||
["user_id"],
|
|
||||||
unique=False,
|
|
||||||
)
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_index(op.f("ix_userproductusage_user_id"), table_name="userproductusage")
|
|
||||||
op.drop_index("ix_userproductusage_product_user", table_name="userproductusage")
|
|
||||||
op.drop_index(op.f("ix_presetentry_product_id"), table_name="presetentry")
|
|
||||||
op.drop_index(op.f("ix_presetentry_preset_id"), table_name="presetentry")
|
|
||||||
op.drop_index(op.f("ix_preset_user_id"), table_name="preset")
|
|
||||||
op.drop_index(op.f("ix_meal_diary_id"), table_name="meal")
|
|
||||||
op.add_column(
|
|
||||||
"entry",
|
|
||||||
sa.Column("processed", sa.BOOLEAN(), autoincrement=False, nullable=False),
|
|
||||||
)
|
|
||||||
op.drop_index(op.f("ix_entry_product_id"), table_name="entry")
|
|
||||||
op.drop_index(op.f("ix_entry_meal_id"), table_name="entry")
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
"""merge heads
|
|
||||||
|
|
||||||
Revision ID: 7bda12666bf0
|
|
||||||
Revises: 564e5948f3ed, a1b2c3d4e5f6
|
|
||||||
Create Date: 2026-04-07 20:50:01.702218
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "7bda12666bf0"
|
|
||||||
down_revision: Union[str, Sequence[str], None] = (
|
|
||||||
"564e5948f3ed",
|
|
||||||
"a1b2c3d4e5f6",
|
|
||||||
)
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
pass
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
"""
|
|
||||||
|
|
||||||
Revision ID: 97d77db27867
|
|
||||||
Revises:
|
|
||||||
Create Date: 2026-04-02 19:03:34.833774
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "97d77db27867"
|
|
||||||
down_revision: Union[str, Sequence[str], None] = None
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
"""add unique constraint to user.username
|
|
||||||
|
|
||||||
Revision ID: a1b2c3d4e5f6
|
|
||||||
Revises: 4e8d78ff6e9e
|
|
||||||
Create Date: 2026-04-07 15:00:00.000000
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
revision: str = "a1b2c3d4e5f6"
|
|
||||||
down_revision: Union[str, Sequence[str], None] = "4e8d78ff6e9e"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
op.create_unique_constraint("uq_user_username", "user", ["username"])
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
op.drop_constraint("uq_user_username", "user", type_="unique")
|
|
||||||
255
fooder/alembic/versions/d70663890e9d_.py
Normal file
255
fooder/alembic/versions/d70663890e9d_.py
Normal file
|
|
@ -0,0 +1,255 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: d70663890e9d
|
||||||
|
Revises:
|
||||||
|
Create Date: 2026-04-16 13:17:38.973404
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "d70663890e9d"
|
||||||
|
down_revision: Union[str, Sequence[str], None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table(
|
||||||
|
"product",
|
||||||
|
sa.Column("name", sa.String(), nullable=False),
|
||||||
|
sa.Column("protein", sa.Float(), nullable=False),
|
||||||
|
sa.Column("carb", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fat", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fiber", sa.Float(), nullable=False),
|
||||||
|
sa.Column("calories", sa.Float(), nullable=False),
|
||||||
|
sa.Column("barcode", sa.String(), nullable=True),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("deleted_at", sa.DateTime(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_product_barcode",
|
||||||
|
"product",
|
||||||
|
["barcode"],
|
||||||
|
unique=True,
|
||||||
|
postgresql_where=sa.text("deleted_at IS NULL"),
|
||||||
|
sqlite_where=sa.text("deleted_at IS NULL"),
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"user",
|
||||||
|
sa.Column("username", sa.String(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("hashed_password", sa.String(), nullable=False),
|
||||||
|
sa.Column("deleted_at", sa.DateTime(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("username"),
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"diary",
|
||||||
|
sa.Column("date", sa.Date(), nullable=False),
|
||||||
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("protein_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("carb_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fat_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fiber_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("calories_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["user_id"],
|
||||||
|
["user.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("user_id", "date"),
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"preset",
|
||||||
|
sa.Column("name", sa.String(), nullable=False),
|
||||||
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["user_id"],
|
||||||
|
["user.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_preset_user_id"), "preset", ["user_id"], unique=False
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"userproductusage",
|
||||||
|
sa.Column("product_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("count", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["product_id"],
|
||||||
|
["product.id"],
|
||||||
|
),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["user_id"],
|
||||||
|
["user.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("user_id", "product_id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_userproductusage_product_user",
|
||||||
|
"userproductusage",
|
||||||
|
["product_id", "user_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_userproductusage_user_id"),
|
||||||
|
"userproductusage",
|
||||||
|
["user_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"usersettings",
|
||||||
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("protein_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("carb_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fat_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("fiber_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("calories_goal", sa.Float(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["user_id"],
|
||||||
|
["user.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("user_id"),
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"meal",
|
||||||
|
sa.Column("name", sa.String(), nullable=False),
|
||||||
|
sa.Column("order", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("diary_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["diary_id"],
|
||||||
|
["diary.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_meal_diary_id"), "meal", ["diary_id"], unique=False
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"presetentry",
|
||||||
|
sa.Column("grams", sa.Float(), nullable=False),
|
||||||
|
sa.Column("product_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("preset_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["preset_id"],
|
||||||
|
["preset.id"],
|
||||||
|
),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["product_id"],
|
||||||
|
["product.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_presetentry_preset_id"),
|
||||||
|
"presetentry",
|
||||||
|
["preset_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_presetentry_product_id"),
|
||||||
|
"presetentry",
|
||||||
|
["product_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_table(
|
||||||
|
"entry",
|
||||||
|
sa.Column("grams", sa.Float(), nullable=False),
|
||||||
|
sa.Column("product_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("meal_id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("version", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
sa.Column("last_changed", sa.DateTime(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["meal_id"],
|
||||||
|
["meal.id"],
|
||||||
|
),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["product_id"],
|
||||||
|
["product.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_entry_meal_id"), "entry", ["meal_id"], unique=False
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_entry_product_id"), "entry", ["product_id"], unique=False
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index(op.f("ix_entry_product_id"), table_name="entry")
|
||||||
|
op.drop_index(op.f("ix_entry_meal_id"), table_name="entry")
|
||||||
|
op.drop_table("entry")
|
||||||
|
op.drop_index(op.f("ix_presetentry_product_id"), table_name="presetentry")
|
||||||
|
op.drop_index(op.f("ix_presetentry_preset_id"), table_name="presetentry")
|
||||||
|
op.drop_table("presetentry")
|
||||||
|
op.drop_index(op.f("ix_meal_diary_id"), table_name="meal")
|
||||||
|
op.drop_table("meal")
|
||||||
|
op.drop_table("usersettings")
|
||||||
|
op.drop_index(
|
||||||
|
op.f("ix_userproductusage_user_id"), table_name="userproductusage"
|
||||||
|
)
|
||||||
|
op.drop_index(
|
||||||
|
"ix_userproductusage_product_user", table_name="userproductusage"
|
||||||
|
)
|
||||||
|
op.drop_table("userproductusage")
|
||||||
|
op.drop_index(op.f("ix_preset_user_id"), table_name="preset")
|
||||||
|
op.drop_table("preset")
|
||||||
|
op.drop_table("diary")
|
||||||
|
op.drop_table("user")
|
||||||
|
op.drop_index(
|
||||||
|
"ix_product_barcode",
|
||||||
|
table_name="product",
|
||||||
|
postgresql_where=sa.text("deleted_at IS NULL"),
|
||||||
|
sqlite_where=sa.text("deleted_at IS NULL"),
|
||||||
|
)
|
||||||
|
op.drop_table("product")
|
||||||
|
# ### end Alembic commands ###
|
||||||
Loading…
Reference in a new issue