add created_by to longs
change
commit 70020adbe78600713b3dadf77095bc98b1d05bf9
author Alpha Chen <alpha@kejadlen.dev>
date
parent c8630afd
diff --git a/alembic/env.py b/alembic/env.py
index 48fbd5e..2c3b2ae 100644
--- a/alembic/env.py
+++ b/alembic/env.py
@@ -14,7 +14,6 @@ if config.config_file_name is not None:
     fileConfig(config.config_file_name)
 
 from go_ji.db import Base  # noqa: E402
-from go_ji.models import *  # noqa: E402, F403
 
 target_metadata = Base.metadata
 
diff --git a/alembic/versions/68d7e4ed662a_add_created_by_to_long.py b/alembic/versions/68d7e4ed662a_add_created_by_to_long.py
new file mode 100644
index 0000000..6c153a8
--- /dev/null
+++ b/alembic/versions/68d7e4ed662a_add_created_by_to_long.py
@@ -0,0 +1,37 @@
+"""Add created_by to long
+
+Revision ID: 68d7e4ed662a
+Revises: bf7c50886b7d
+Create Date: 2024-02-15 08:31:57.799981
+
+"""
+from typing import Sequence, Union
+
+import sqlalchemy as sa
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision: str = "68d7e4ed662a"
+down_revision: Union[str, None] = "bf7c50886b7d"
+branch_labels: Union[str, Sequence[str], None] = None
+depends_on: Union[str, Sequence[str], None] = None
+
+
+def upgrade() -> None:
+    with op.batch_alter_table("longs") as batch_op:
+        batch_op.add_column(sa.Column("created_by_id", sa.Integer(), nullable=False))
+        batch_op.create_foreign_key(
+            op.f("fk_longs_created_by_id_users"),
+            "users",
+            ["created_by_id"],
+            ["id"],
+        )
+
+
+def downgrade() -> None:
+    with op.batch_alter_table("longs") as batch_op:
+        batch_op.drop_constraint(
+            op.f("fk_longs_created_by_id_users"), type_="foreignkey"
+        )
+        batch_op.drop_column("created_by_id")
diff --git a/go_ji/db.py b/go_ji/db.py
index ed596c8..5ae2569 100644
--- a/go_ji/db.py
+++ b/go_ji/db.py
@@ -56,6 +56,9 @@ class Long(Base):
     short_id: Mapped[int] = mapped_column(ForeignKey("shorts.id"), nullable=False)
     short: Mapped["Short"] = relationship(back_populates="longs")
 
+    created_by_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
+    created_by: Mapped["User"] = relationship()
+
     created_at: Mapped[datetime] = mapped_column(nullable=False, default=func.now())