init
Some checks failed
Build and Release / release (push) Failing after 51s

This commit is contained in:
2026-03-25 22:29:07 +07:00
parent eedd300861
commit 79199f627d
65 changed files with 3215 additions and 689 deletions

View File

@@ -3,7 +3,7 @@ CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY DEFAULT uuidv7(),
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
password_hash TEXT,
google_id VARCHAR(255) UNIQUE,
auth_provider VARCHAR(50) NOT NULL DEFAULT 'local',
is_verified BOOLEAN NOT NULL DEFAULT false,

View File

@@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS user_verifications (
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
verify_type SMALLINT NOT NULL, -- 1 = ID_CARD, 2 = EDUCATION, 3 = EXPERT
document_url TEXT NOT NULL,
is_deleted BOOLEAN NOT NULL DEFAULT false,
status SMALLINT NOT NULL DEFAULT 1, -- 1 pending, 2 approved, 3 rejected
reviewed_by UUID REFERENCES users(id),
reviewed_at TIMESTAMPTZ,
@@ -10,9 +11,18 @@ CREATE TABLE IF NOT EXISTS user_verifications (
);
CREATE INDEX idx_user_verifications_user_id ON user_verifications(user_id);
CREATE INDEX idx_user_verifications_user_type ON user_verifications(user_id, verify_type);
CREATE INDEX idx_user_verifications_status ON user_verifications(status);
CREATE INDEX idx_user_verifications_user_id
ON user_verifications(user_id)
WHERE is_deleted = false;
CREATE INDEX idx_user_verifications_user_type
ON user_verifications(user_id, verify_type)
WHERE is_deleted = false;
CREATE INDEX idx_user_verifications_status
ON user_verifications(status)
WHERE is_deleted = false;
CREATE INDEX idx_user_verifications_status_created
ON user_verifications(status, created_at DESC);
ON user_verifications(status, created_at DESC)
WHERE is_deleted = false;

View File

@@ -3,18 +3,23 @@ CREATE TABLE IF NOT EXISTS user_tokens (
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
token VARCHAR(255) NOT NULL UNIQUE,
token_type SMALLINT NOT NULL,
is_deleted BOOLEAN NOT NULL DEFAULT false,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_user_tokens_token
ON user_tokens(token);
ON user_tokens(token)
WHERE is_deleted = false;
CREATE INDEX idx_user_tokens_user_id
ON user_tokens(user_id);
ON user_tokens(user_id)
WHERE is_deleted = false;
CREATE INDEX idx_user_tokens_type
ON user_tokens(token_type);
ON user_tokens(token_type)
WHERE is_deleted = false;
CREATE INDEX idx_user_tokens_expires_at
ON user_tokens(expires_at);
ON user_tokens(expires_at)
WHERE is_deleted = false;

View File

@@ -11,11 +11,38 @@ CREATE TABLE IF NOT EXISTS entities (
description TEXT,
thumbnail_url TEXT,
status SMALLINT DEFAULT 1, -- 1 draft, 2 published
is_deleted BOOLEAN NOT NULL DEFAULT false,
reviewed_by UUID REFERENCES users(id),
reviewed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_entities_slug ON entities(slug);
CREATE UNIQUE INDEX uniq_entities_slug_active
ON entities(slug)
WHERE is_deleted = false;
CREATE INDEX idx_entities_type
ON entities(type_id)
WHERE is_deleted = false;
CREATE INDEX idx_entities_status_created
ON entities(status, created_at DESC)
WHERE is_deleted = false;
CREATE INDEX idx_entities_type_status
ON entities(type_id, status)
WHERE is_deleted = false;
CREATE INDEX idx_entities_reviewed_by
ON entities(reviewed_by)
WHERE is_deleted = false;
CREATE INDEX idx_entities_name_search
ON entities USING gin (name gin_trgm_ops);
CREATE TRIGGER trigger_entities_updated_at
BEFORE UPDATE ON entities

View File

@@ -1,25 +1,20 @@
CREATE TABLE IF NOT EXISTS wiki_pages (
CREATE TABLE IF NOT EXISTS wikis (
id UUID PRIMARY KEY DEFAULT uuidv7(),
entity_id UUID REFERENCES entities(id) ON DELETE CASCADE,
user_id UUID REFERENCES users(id),
title TEXT,
is_deleted BOOLEAN NOT NULL DEFAULT false,
note TEXT,
content TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE TABLE IF NOT EXISTS wiki_versions (
id UUID PRIMARY KEY DEFAULT uuidv7(),
wiki_id UUID REFERENCES wiki_pages(id) ON DELETE CASCADE,
created_user UUID REFERENCES users(id),
note TEXT,
content TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
approved_at TIMESTAMPTZ
);
CREATE INDEX idx_wiki_entity
ON wikis(entity_id)
WHERE is_deleted = false;
CREATE INDEX idx_wiki_entity ON wiki_pages(entity_id);
CREATE TRIGGER trigger_wiki_pages_updated_at
BEFORE UPDATE ON wiki_pages
CREATE TRIGGER trigger_wikis_updated_at
BEFORE UPDATE ON wikis
FOR EACH ROW
EXECUTE FUNCTION update_updated_at();

View File

@@ -1,8 +1,11 @@
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE IF NOT EXISTS geometries (
id UUID PRIMARY KEY DEFAULT uuidv7(),
geom GEOMETRY, -- point / polygon / line
time_start INT,
time_end INT,
is_deleted BOOLEAN NOT NULL DEFAULT false,
bbox GEOMETRY, -- optional
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
@@ -13,9 +16,11 @@ CREATE TABLE IF NOT EXISTS geo_versions (
geo_id UUID REFERENCES geometries(id) ON DELETE CASCADE,
created_user UUID REFERENCES users(id),
geom GEOMETRY,
is_deleted BOOLEAN NOT NULL DEFAULT false,
note TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
approved_at TIMESTAMPTZ
reviewed_by UUID REFERENCES users(id),
reviewed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE TABLE IF NOT EXISTS entity_geometries (
@@ -24,8 +29,33 @@ CREATE TABLE IF NOT EXISTS entity_geometries (
PRIMARY KEY (entity_id, geometry_id)
);
CREATE INDEX idx_geo_time ON geometries(time_start, time_end);
CREATE INDEX idx_geom_spatial ON geometries USING GIST (geom);
CREATE INDEX idx_geom_spatial_active
ON geometries USING GIST (geom)
WHERE is_deleted = false;
CREATE INDEX idx_geom_bbox
ON geometries USING GIST (bbox)
WHERE is_deleted = false;
CREATE INDEX idx_geom_time_range
ON geometries
USING GIST (int4range(time_start, time_end))
WHERE is_deleted = false;
CREATE INDEX idx_geo_versions_geo_id
ON geo_versions(geo_id)
WHERE is_deleted = false;
CREATE INDEX idx_geo_versions_reviewed_by
ON geo_versions(reviewed_by)
WHERE is_deleted = false;
CREATE INDEX idx_geo_versions_created_at
ON geo_versions(created_at DESC)
WHERE is_deleted = false;
CREATE INDEX idx_entity_geometries_geometry
ON entity_geometries(geometry_id);
CREATE TRIGGER trigger_geometries_updated_at
BEFORE UPDATE ON geometries