user_id set to be nullable (upgrade model and dump)

This commit is contained in:
Ivanov Matvey 2025-03-14 04:43:30 +10:00
parent 4f2900f1b6
commit b4b0b6d06c
3 changed files with 4 additions and 69 deletions

View File

@ -1,40 +0,0 @@
"""empty message
Revision ID: cdf401a636ea
Revises:
Create Date: 2025-03-14 04:16:49.143794
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'cdf401a636ea'
down_revision: Union[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('log',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('datetime', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('action', sa.Enum('FIRST_ENTRY', 'REGISTRATION', 'LOGIN', 'LOGOUT', 'CREATE_THEME', 'ENTRY_THEME', 'DELETE_THEME', 'WRITE_MESSAGE', name='useractions'), nullable=False),
sa.Column('object_id', sa.Integer(), nullable=True),
sa.Column('response', sa.SMALLINT(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('log')
# ### end Alembic commands ###

View File

@ -39,16 +39,6 @@ SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: alembic_version; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.alembic_version (
version_num character varying(32) NOT NULL
);
ALTER TABLE public.alembic_version OWNER TO postgres;
--
-- Name: log; Type: TABLE; Schema: public; Owner: postgres
@ -56,7 +46,7 @@ ALTER TABLE public.alembic_version OWNER TO postgres;
CREATE TABLE public.log (
id integer NOT NULL,
user_id integer NOT NULL,
user_id integer,
datetime timestamp with time zone NOT NULL,
action public.useractions NOT NULL,
object_id integer,
@ -94,33 +84,18 @@ ALTER SEQUENCE public.log_id_seq OWNED BY public.log.id;
ALTER TABLE ONLY public.log ALTER COLUMN id SET DEFAULT nextval('public.log_id_seq'::regclass);
--
-- Data for Name: alembic_version; Type: TABLE DATA; Schema: public; Owner: postgres
--
INSERT INTO public.alembic_version (version_num) VALUES ('cdf401a636ea');
--
-- Data for Name: log; Type: TABLE DATA; Schema: public; Owner: postgres
--
INSERT INTO public.log (id, user_id, datetime, action, object_id, response) VALUES (1, 2, '2025-03-13 18:34:34.443097+00', 'FIRST_ENTRY', NULL, 200);
--
-- Name: log_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--
SELECT pg_catalog.setval('public.log_id_seq', 1, false);
--
-- Name: alembic_version alembic_version_pkc; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.alembic_version
ADD CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num);
SELECT pg_catalog.setval('public.log_id_seq', 1, true);
--

View File

@ -25,7 +25,7 @@ class Base(DeclarativeBase):
class Log(Base):
__tablename__ = "log"
id: Mapped[int] = mapped_column(INTEGER, primary_key=True, autoincrement=True)
user_id: Mapped[int]
user_id: Mapped[int] = mapped_column(nullable=True)
date_time: Mapped[datetime] = mapped_column(
"datetime", TIMESTAMP(timezone=True), default=utc_signed_now
)