UPDATE: Entity, Geo, Wiki
Some checks failed
Build and Release / release (push) Failing after 1m7s

This commit is contained in:
2026-04-22 17:45:09 +07:00
parent f127e2f029
commit adb65d8292
50 changed files with 3354 additions and 119 deletions

View File

@@ -1,2 +1 @@
DROP TABLE IF EXISTS entity_types;
DROP TABLE IF EXISTS entities;

View File

@@ -1,48 +1,20 @@
CREATE TABLE IF NOT EXISTS entity_types (
id SMALLSERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL
);
CREATE TABLE IF NOT EXISTS entities (
id UUID PRIMARY KEY DEFAULT uuidv7(),
type_id SMALLINT REFERENCES entity_types(id),
name TEXT NOT NULL,
slug TEXT UNIQUE,
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 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);
ON entities USING GIN (name gin_trgm_ops);
CREATE INDEX idx_entities_created_active
ON entities(created_at DESC)
WHERE is_deleted = false;
CREATE TRIGGER trigger_entities_updated_at
BEFORE UPDATE ON entities

View File

@@ -1,2 +1,2 @@
DROP TABLE IF EXISTS wiki_pages;
DROP TABLE IF EXISTS wiki_versions;
DROP TABLE IF EXISTS wikis;
DROP TABLE IF EXISTS entity_wikis;

View File

@@ -1,17 +1,30 @@
CREATE EXTENSION IF NOT EXISTS pg_trgm;
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,
is_deleted BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_wiki_entity
ON wikis(entity_id)
CREATE TABLE IF NOT EXISTS entity_wikis (
entity_id UUID REFERENCES entities(id) ON DELETE CASCADE,
wiki_id UUID REFERENCES wikis(id) ON DELETE CASCADE,
PRIMARY KEY (entity_id, wiki_id)
);
CREATE INDEX idx_entity_wikis_wiki_id
ON entity_wikis(wiki_id);
CREATE INDEX idx_wikis_created_active
ON wikis(created_at DESC)
WHERE is_deleted = false;
CREATE INDEX idx_wikis_title_search
ON wikis USING GIN (title gin_trgm_ops)
WHERE is_deleted = false;
CREATE TRIGGER trigger_wikis_updated_at

View File

@@ -1,3 +1,2 @@
DROP TABLE IF EXISTS geometries;
DROP TABLE IF EXISTS geo_versions;
DROP TABLE IF EXISTS entity_geometries;

View File

@@ -1,27 +1,22 @@
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE IF NOT EXISTS geometries (
id UUID PRIMARY KEY DEFAULT uuidv7(),
geom GEOMETRY, -- point / polygon / line
geo_type VARCHAR(50) NOT NULL DEFAULT 'id'
draw_geometry JSONB NOT NULL,
binding JSONB,
time_start INT,
time_end INT,
bbox GEOMETRY,
is_deleted BOOLEAN NOT NULL DEFAULT false,
bbox GEOMETRY, -- optional
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE TABLE IF NOT EXISTS geo_versions (
id UUID PRIMARY KEY DEFAULT uuidv7(),
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,
reviewed_by UUID REFERENCES users(id),
reviewed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT now()
);
ALTER TABLE geometries DROP CONSTRAINT IF EXISTS check_geo_type;
ALTER TABLE geometries ADD CONSTRAINT check_geo_type
CHECK (geo_type IN ('id', 'name', 'icon', 'variant', 'description'));
CREATE TABLE IF NOT EXISTS entity_geometries (
entity_id UUID REFERENCES entities(id) ON DELETE CASCADE,
@@ -29,34 +24,27 @@ CREATE TABLE IF NOT EXISTS entity_geometries (
PRIMARY KEY (entity_id, geometry_id)
);
CREATE INDEX idx_geom_spatial_active
ON geometries USING GIST (geom)
WHERE is_deleted = false;
CREATE INDEX idx_geom_draw_geometry
ON geometries USING GIN (draw_geometry);
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)
ON geometries USING GIST (int4range(time_start, time_end))
WHERE is_deleted = false;
CREATE INDEX idx_entity_geometries_geometry
ON entity_geometries(geometry_id);
CREATE INDEX idx_geom_binding
ON geometries USING GIN (binding);
CREATE INDEX idx_geom_updated_at
ON geometries (updated_at DESC)
WHERE is_deleted = false;
CREATE TRIGGER trigger_geometries_updated_at
BEFORE UPDATE ON geometries
FOR EACH ROW