50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""seed explain test 10k
|
|
|
|
Revision ID: 509b7b85e81f
|
|
Revises: 9f0905ee61f9
|
|
Create Date: 2026-10-23 10:19:10.693752
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '509b7b85e81f'
|
|
down_revision: Union[str, None] = '9f0905ee61f9'
|
|
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';")
|