feat: implement auth, projects, and frontend foundation
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
"""initial schema
|
||||
|
||||
Revision ID: 0001_initial_schema
|
||||
Revises:
|
||||
Create Date: 2026-05-17 00:00:00.000000
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "0001_initial_schema"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
TABLE_NAMES = [
|
||||
"users",
|
||||
"ssh_keys",
|
||||
"projects",
|
||||
"git_repositories",
|
||||
"user_configs",
|
||||
]
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"users",
|
||||
sa.Column("email", sa.String(length=255), nullable=False),
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("authentik_id", sa.String(length=255), nullable=False),
|
||||
sa.Column("avatar_url", sa.String(length=1024), nullable=True),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("authentik_id"),
|
||||
sa.UniqueConstraint("email"),
|
||||
)
|
||||
op.create_index(op.f("ix_users_authentik_id"), "users", ["authentik_id"], unique=True)
|
||||
op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
|
||||
|
||||
op.create_table(
|
||||
"ssh_keys",
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("public_key", sa.Text(), nullable=False),
|
||||
sa.Column("private_key_encrypted", sa.Text(), nullable=False),
|
||||
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("project_id", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"projects",
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("owner_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("default_ssh_key_id", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.ForeignKeyConstraint(["default_ssh_key_id"], ["ssh_keys.id"]),
|
||||
sa.ForeignKeyConstraint(["owner_id"], ["users.id"]),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"git_repositories",
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("path", sa.String(length=1024), nullable=False),
|
||||
sa.Column("project_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("owner_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("is_mirror", sa.Boolean(), nullable=False),
|
||||
sa.Column("remote_url", sa.String(length=1024), nullable=True),
|
||||
sa.Column("last_push", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.ForeignKeyConstraint(["owner_id"], ["users.id"]),
|
||||
sa.ForeignKeyConstraint(["project_id"], ["projects.id"]),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"user_configs",
|
||||
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("config", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("user_id"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("user_configs")
|
||||
op.drop_table("git_repositories")
|
||||
op.drop_table("projects")
|
||||
op.drop_table("ssh_keys")
|
||||
op.drop_index(op.f("ix_users_email"), table_name="users")
|
||||
op.drop_index(op.f("ix_users_authentik_id"), table_name="users")
|
||||
op.drop_table("users")
|
||||
@@ -0,0 +1,58 @@
|
||||
"""add refresh tokens table
|
||||
|
||||
Revision ID: 0002_refresh_tokens
|
||||
Revises: 0001_initial_schema
|
||||
Create Date: 2026-05-17 00:00:01.000000
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "0002_refresh_tokens"
|
||||
down_revision = "0001_initial_schema"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
connection = op.get_bind()
|
||||
inspector = sa.inspect(connection)
|
||||
|
||||
if not inspector.has_table("refresh_tokens"):
|
||||
op.create_table(
|
||||
"refresh_tokens",
|
||||
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("token_hash", sa.String(length=255), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("revoked_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("user_agent", sa.String(length=512), nullable=True),
|
||||
sa.Column("ip_address", sa.String(length=64), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("token_hash"),
|
||||
)
|
||||
|
||||
existing_indexes = {index["name"] for index in inspector.get_indexes("refresh_tokens")}
|
||||
user_index = op.f("ix_refresh_tokens_user_id")
|
||||
expires_index = op.f("ix_refresh_tokens_expires_at")
|
||||
if user_index not in existing_indexes:
|
||||
op.create_index(user_index, "refresh_tokens", ["user_id"], unique=False)
|
||||
if expires_index not in existing_indexes:
|
||||
op.create_index(expires_index, "refresh_tokens", ["expires_at"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
connection = op.get_bind()
|
||||
inspector = sa.inspect(connection)
|
||||
if inspector.has_table("refresh_tokens"):
|
||||
existing_indexes = {index["name"] for index in inspector.get_indexes("refresh_tokens")}
|
||||
expires_index = op.f("ix_refresh_tokens_expires_at")
|
||||
user_index = op.f("ix_refresh_tokens_user_id")
|
||||
if expires_index in existing_indexes:
|
||||
op.drop_index(expires_index, table_name="refresh_tokens")
|
||||
if user_index in existing_indexes:
|
||||
op.drop_index(user_index, table_name="refresh_tokens")
|
||||
op.drop_table("refresh_tokens")
|
||||
Reference in New Issue
Block a user