forked from mtusi2026/mtusi2026lab2
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""seed explain test 10k
|
|
|
|
Revision ID: bc35c1b6b748
|
|
Revises: f9b85be2b710
|
|
Create Date: 2026-10-24 07:04:09.294404
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'bc35c1b6b748'
|
|
down_revision: Union[str, None] = 'f9b85be2b710'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute("""
|
|
INSERT INTO users (id, username, display_name, password_hash, created_at)
|
|
VALUES ('11111111-1111-1111-1111-111111111111', 'explain_test', 'Test', 'hash', NOW())
|
|
ON CONFLICT DO NOTHING;
|
|
""")
|
|
|
|
op.execute("""
|
|
INSERT INTO chats (id, title, created_at)
|
|
VALUES ('22222222-2222-2222-2222-222222222222', 'Explain Chat', NOW())
|
|
ON CONFLICT DO NOTHING;
|
|
""")
|
|
|
|
op.execute("""
|
|
INSERT INTO messages (id, chat_id, sender_id, text, created_at)
|
|
SELECT gen_random_uuid(), '22222222-2222-2222-2222-222222222222', '11111111-1111-1111-1111-111111111111', 'Message ' || i, NOW() - (i || ' minutes')::interval
|
|
FROM generate_series(1, 10000) AS i;
|
|
""")
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DELETE FROM messages WHERE chat_id = '22222222-2222-2222-2222-222222222222';")
|
|
op.execute("DELETE FROM chats WHERE id = '22222222-2222-2222-2222-222222222222';")
|
|
op.execute("DELETE FROM users WHERE id = '11111111-1111-1111-1111-111111111111';") |