a working product with ugly ui

This commit is contained in:
2025-12-12 20:15:27 +05:00
parent e6d04f986f
commit 4d3085623a
77 changed files with 8750 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
"""Initial schema with PostGIS support
Revision ID: 915e5889d6d7
Revises:
Create Date: 2025-12-12 01:25:16.706772
"""
from alembic import op
import sqlalchemy as sa
import geoalchemy2
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '915e5889d6d7'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Enable PostGIS extension
op.execute('CREATE EXTENSION IF NOT EXISTS postgis')
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('username', sa.String(length=50), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('password_hash', sa.String(length=255), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
op.create_table('maps',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('owner_id', sa.UUID(), nullable=False),
sa.Column('is_default_public', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_maps_owner_id'), 'maps', ['owner_id'], unique=False)
op.create_table('map_items',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('map_id', sa.UUID(), nullable=False),
sa.Column('type', sa.String(length=50), nullable=False),
sa.Column('geometry', geoalchemy2.types.Geography(srid=4326, from_text='ST_GeogFromText', name='geography', nullable=False), nullable=False),
sa.Column('properties', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('created_by', sa.UUID(), nullable=True),
sa.Column('updated_by', sa.UUID(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['map_id'], ['maps.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['updated_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# Note: GeoAlchemy2 automatically creates a GIST index on Geography columns
# So we don't need to create it explicitly here
# op.create_index('idx_map_items_geometry', 'map_items', ['geometry'], unique=False, postgresql_using='gist')
op.create_index(op.f('ix_map_items_map_id'), 'map_items', ['map_id'], unique=False)
op.create_index(op.f('ix_map_items_type'), 'map_items', ['type'], unique=False)
op.create_table('sessions',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('user_id', sa.UUID(), nullable=True),
sa.Column('map_id', sa.UUID(), nullable=False),
sa.Column('socket_id', sa.String(length=255), nullable=False),
sa.Column('username', sa.String(length=50), nullable=True),
sa.Column('connected_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('last_seen', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['map_id'], ['maps.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_sessions_map_id'), 'sessions', ['map_id'], unique=False)
op.create_index(op.f('ix_sessions_user_id'), 'sessions', ['user_id'], unique=False)
op.create_table('shares',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('map_id', sa.UUID(), nullable=False),
sa.Column('share_token', sa.String(length=64), nullable=False),
sa.Column('access_level', sa.String(length=20), nullable=False),
sa.Column('requires_auth', sa.Boolean(), nullable=False),
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('created_by', sa.UUID(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['map_id'], ['maps.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_shares_map_id'), 'shares', ['map_id'], unique=False)
op.create_index(op.f('ix_shares_share_token'), 'shares', ['share_token'], unique=True)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# Drop our application tables
op.drop_index(op.f('ix_shares_share_token'), table_name='shares')
op.drop_index(op.f('ix_shares_map_id'), table_name='shares')
op.drop_table('shares')
op.drop_index(op.f('ix_sessions_user_id'), table_name='sessions')
op.drop_index(op.f('ix_sessions_map_id'), table_name='sessions')
op.drop_table('sessions')
op.drop_index(op.f('ix_map_items_type'), table_name='map_items')
op.drop_index(op.f('ix_map_items_map_id'), table_name='map_items')
op.drop_index('idx_map_items_geometry', table_name='map_items', postgresql_using='gist')
op.drop_table('map_items')
op.drop_index(op.f('ix_maps_owner_id'), table_name='maps')
op.drop_table('maps')
op.drop_index(op.f('ix_users_username'), table_name='users')
op.drop_index(op.f('ix_users_email'), table_name='users')
op.drop_table('users')
# Optionally drop PostGIS extension (commented out to preserve it)
# op.execute('DROP EXTENSION IF EXISTS postgis CASCADE')
# ### end Alembic commands ###