mirror of
https://github.com/xlorepdarkhelm/numinar-coding-project.git
synced 2026-09-05 22:48:25 -04:00
Added seed.sql and loaded dummy data.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
35
backend/migrations/seed.sql
Normal file
35
backend/migrations/seed.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
-- Test/dummy data for users and rooms
|
||||
|
||||
INSERT INTO users (email, name) VALUES
|
||||
('john.doe@email.com', 'John Doe'),
|
||||
('jane.smith@email.com', 'Jane Smith'),
|
||||
('alice.jones@email.com', 'Alice Jones'),
|
||||
('bob.brown@email.com', 'Bob Brown'),
|
||||
('charlie.johnson@email.com', 'Charlie Johnson'),
|
||||
('diana.wilson@email.com', 'Diana Wilson'),
|
||||
('eric.miller@email.com', 'Eric Miller'),
|
||||
('fiona.davis@email.com', 'Fiona Davis'),
|
||||
('george.rodriguez@email.com', 'George Rodriguez'),
|
||||
('hannah.garcia@email.com', 'Hannah Garcia'),
|
||||
('ian.martinez@email.com', 'Ian Martinez'),
|
||||
('julia.robinson@email.com', 'Julia Robinson'),
|
||||
('kevin.clark@email.com', 'Kevin Clark'),
|
||||
('linda.lewis@email.com', 'Linda Lewis'),
|
||||
('michael.lee@email.com', 'Michael Lee'),
|
||||
('natalie.walker@email.com', 'Natalie Walker'),
|
||||
('oscar.hall@email.com', 'Oscar Hall'),
|
||||
('paula.young@email.com', 'Paula Young'),
|
||||
('quentin.allen@email.com', 'Quentin Allen'),
|
||||
('rachel.hernandez@email.com', 'Rachel Hernandez');
|
||||
|
||||
INSERT INTO rooms (id, name, location, equipment, capacity) VALUES
|
||||
(1, 'Alpha Room', 'Floor 1', 'Projector', 2),
|
||||
(2, 'Beta Room', 'Floor 1', 'Whiteboard', 3),
|
||||
(3, 'Gamma Room', 'Floor 2', 'TV Screen', 2),
|
||||
(4, 'Delta Room', 'Floor 2', 'Projector', 2),
|
||||
(5, 'Epsilon Room', 'Floor 3', 'Phone', 4),
|
||||
(6, 'Zeta Room', 'Floor 3', 'Whiteboard, Projector', 5),
|
||||
(7, 'Eta Room', 'Floor 4', 'TV Screen', 3),
|
||||
(8, 'Theta Room', 'Floor 4', 'Projector', 4),
|
||||
(9, 'Iota Room', 'Floor 5', 'Whiteboard', 2),
|
||||
(10, 'Kappa Room', 'Floor 5', 'Whiteboard, TV Screen', 6);
|
||||
@@ -1,15 +1,14 @@
|
||||
"""Initial Migration
|
||||
"""Add seed data from seed.sql with separate prepared statements
|
||||
|
||||
Revision ID: e6a14f4dae3d
|
||||
Revises:
|
||||
Create Date: 2025-08-22 23:40:52.885449
|
||||
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
from typing import Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
@@ -21,14 +20,24 @@ depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
"""Upgrade schema by loading and executing seed.sql as separate prepared statements."""
|
||||
# Get the parent directory of the current migration script's directory
|
||||
migration_dir = Path(__file__).parent.parent.resolve()
|
||||
seed_file_path = migration_dir / "seed.sql"
|
||||
|
||||
# Read the seed.sql file
|
||||
with seed_file_path.open("r") as file:
|
||||
sql_content = file.read()
|
||||
|
||||
# Split the SQL content into individual statements
|
||||
sql_statements = [stmt.strip() for stmt in sql_content.split(";") if stmt.strip()]
|
||||
|
||||
# Execute each statement individually
|
||||
for stmt in sql_statements:
|
||||
op.execute(stmt)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
"""Downgrade schema by removing data from users and rooms tables."""
|
||||
op.execute("DELETE FROM users")
|
||||
op.execute("DELETE FROM rooms")
|
||||
|
||||
@@ -28,8 +28,7 @@ class User(Base):
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, init=False, autoincrement=True)
|
||||
email: Mapped[str] = mapped_column(index=True, unique=True)
|
||||
email: Mapped[str] = mapped_column(primary_key=True)
|
||||
name: Mapped[str]
|
||||
|
||||
invitees: Mapped[list["Invitee"]] = relationship(
|
||||
@@ -76,7 +75,7 @@ class Invitee(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, init=False, autoincrement=True)
|
||||
booking_id: Mapped[int] = mapped_column(ForeignKey("bookings.id"))
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
||||
user_email: Mapped[str] = mapped_column(ForeignKey("users.email"))
|
||||
|
||||
booking: Mapped["Booking"] = relationship(back_populates="invitees", init=False)
|
||||
user: Mapped["User"] = relationship(back_populates="invitees", init=False)
|
||||
|
||||
Reference in New Issue
Block a user