|
| 1 | +-- Game Foundry Studio DEV database DDL |
| 2 | +-- Group: Sprites |
| 3 | +-- Ownership: docs_build/database/ddl/sprites.sql |
| 4 | +-- Target DEV database: gamefoundry_dev |
| 5 | +-- Scope: executable grouped table DDL for active Supabase/server API migration. |
| 6 | +-- Authoritative key values are generated by the server/API layer. |
| 7 | +-- Owned tables: sprite_records, sprite_usage_references |
| 8 | +CREATE TABLE IF NOT EXISTS sprite_records ( |
| 9 | + key text PRIMARY KEY, |
| 10 | + "gameId" text REFERENCES game_workspace_games(key), |
| 11 | + "ownerUserId" text REFERENCES users(key), |
| 12 | + "name" text NOT NULL, |
| 13 | + "status" text NOT NULL, |
| 14 | + "category" text NOT NULL DEFAULT '', |
| 15 | + "tagKeys" jsonb NOT NULL DEFAULT '[]'::jsonb, |
| 16 | + "source" text NOT NULL DEFAULT '', |
| 17 | + "storageObjectKey" text NOT NULL DEFAULT '', |
| 18 | + "storagePath" text NOT NULL DEFAULT '', |
| 19 | + "originalName" text NOT NULL DEFAULT '', |
| 20 | + "mimeType" text NOT NULL DEFAULT '', |
| 21 | + "width" integer, |
| 22 | + "height" integer, |
| 23 | + "sizeBytes" bigint, |
| 24 | + "checksum" text NOT NULL DEFAULT '', |
| 25 | + "paletteColorKeys" jsonb NOT NULL DEFAULT '[]'::jsonb, |
| 26 | + "archived" boolean NOT NULL DEFAULT false, |
| 27 | + "archivedAt" timestamptz, |
| 28 | + "createdAt" timestamptz NOT NULL DEFAULT now(), |
| 29 | + "updatedAt" timestamptz NOT NULL DEFAULT now(), |
| 30 | + "createdBy" text NOT NULL REFERENCES users(key), |
| 31 | + "updatedBy" text NOT NULL REFERENCES users(key) |
| 32 | +); |
| 33 | + |
| 34 | +CREATE INDEX IF NOT EXISTS idx_sprite_records_gameid ON sprite_records ("gameId"); |
| 35 | +CREATE INDEX IF NOT EXISTS idx_sprite_records_owneruserid ON sprite_records ("ownerUserId"); |
| 36 | +CREATE INDEX IF NOT EXISTS idx_sprite_records_status ON sprite_records ("status"); |
| 37 | +CREATE INDEX IF NOT EXISTS idx_sprite_records_createdby ON sprite_records ("createdBy"); |
| 38 | +CREATE INDEX IF NOT EXISTS idx_sprite_records_updatedby ON sprite_records ("updatedBy"); |
| 39 | + |
| 40 | +CREATE TABLE IF NOT EXISTS sprite_usage_references ( |
| 41 | + key text PRIMARY KEY, |
| 42 | + "spriteKey" text NOT NULL REFERENCES sprite_records(key), |
| 43 | + "sourceType" text NOT NULL, |
| 44 | + "sourceKey" text NOT NULL, |
| 45 | + "label" text NOT NULL DEFAULT '', |
| 46 | + "createdAt" timestamptz NOT NULL DEFAULT now(), |
| 47 | + "updatedAt" timestamptz NOT NULL DEFAULT now(), |
| 48 | + "createdBy" text NOT NULL REFERENCES users(key), |
| 49 | + "updatedBy" text NOT NULL REFERENCES users(key) |
| 50 | +); |
| 51 | + |
| 52 | +CREATE INDEX IF NOT EXISTS idx_sprite_usage_references_spritekey ON sprite_usage_references ("spriteKey"); |
| 53 | +CREATE INDEX IF NOT EXISTS idx_sprite_usage_references_source ON sprite_usage_references ("sourceType", "sourceKey"); |
| 54 | +CREATE INDEX IF NOT EXISTS idx_sprite_usage_references_createdby ON sprite_usage_references ("createdBy"); |
| 55 | +CREATE INDEX IF NOT EXISTS idx_sprite_usage_references_updatedby ON sprite_usage_references ("updatedBy"); |
0 commit comments