7 lines
1.6 KiB
SQL
7 lines
1.6 KiB
SQL
CREATE TABLE species (id text PRIMARY KEY, name text NOT NULL, compatibility_group text NOT NULL, catalog_version integer NOT NULL, config_jsonb jsonb NOT NULL);
|
|
CREATE TABLE players (id uuid PRIMARY KEY, display_name text NOT NULL, created_at timestamptz NOT NULL DEFAULT now());
|
|
CREATE TABLE plants (id uuid PRIMARY KEY, owner_id uuid NOT NULL REFERENCES players(id), species_id text NOT NULL REFERENCES species(id), genome_version integer NOT NULL, genome jsonb NOT NULL, mutations jsonb NOT NULL, visual_seed integer NOT NULL, renderer_version integer NOT NULL, rarity_policy_version integer NOT NULL, rarity_score integer NOT NULL CHECK (rarity_score BETWEEN 0 AND 100), rarity_tier text NOT NULL CHECK (rarity_tier IN ('Common','Uncommon','Rare','Epic','Legendary','Mythic')), generation integer NOT NULL CHECK (generation >= 0), parent_a_id uuid REFERENCES plants(id), parent_b_id uuid REFERENCES plants(id), created_at timestamptz NOT NULL DEFAULT now(), CHECK ((parent_a_id IS NULL) = (parent_b_id IS NULL)));
|
|
CREATE INDEX plants_owner_created ON plants(owner_id, created_at DESC);
|
|
CREATE INDEX plants_species_rarity ON plants(species_id, rarity_tier);
|
|
CREATE TABLE breeding_events (id uuid PRIMARY KEY, owner_id uuid NOT NULL REFERENCES players(id), parent_a_id uuid NOT NULL REFERENCES plants(id), parent_b_id uuid NOT NULL REFERENCES plants(id), child_id uuid NOT NULL UNIQUE REFERENCES plants(id), rng_seed integer NOT NULL, engine_version integer NOT NULL, mutation_events jsonb NOT NULL, idempotency_key text NOT NULL UNIQUE, created_at timestamptz NOT NULL DEFAULT now());
|
|
CREATE INDEX breeding_owner_created ON breeding_events(owner_id, created_at DESC);
|