|
| 1 | +-- SQLite Migration |
| 2 | +-- This migration creates the same tables as the PostgreSQL and MySQL migrations |
| 3 | +-- but using SQLite-compatible syntax. |
| 4 | + |
| 5 | +-- Factions Table |
| 6 | +CREATE TABLE IF NOT EXISTS factions ( |
| 7 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 8 | + name TEXT UNIQUE NOT NULL, |
| 9 | + description TEXT |
| 10 | +); |
| 11 | + |
| 12 | +-- Races Table |
| 13 | +CREATE TABLE IF NOT EXISTS races ( |
| 14 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 15 | + name TEXT UNIQUE NOT NULL, |
| 16 | + faction_id INTEGER REFERENCES factions(id) ON DELETE CASCADE |
| 17 | +); |
| 18 | + |
| 19 | +-- Classes Table |
| 20 | +CREATE TABLE IF NOT EXISTS classes ( |
| 21 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 22 | + name TEXT UNIQUE NOT NULL, |
| 23 | + specialization TEXT |
| 24 | +); |
| 25 | + |
| 26 | +-- Characters Table |
| 27 | +CREATE TABLE IF NOT EXISTS characters ( |
| 28 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 29 | + name TEXT NOT NULL, |
| 30 | + race_id INTEGER REFERENCES races(id), |
| 31 | + class_id INTEGER REFERENCES classes(id), |
| 32 | + level INTEGER DEFAULT 1, |
| 33 | + experience INTEGER DEFAULT 0, |
| 34 | + gold REAL DEFAULT 0, |
| 35 | + created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| 36 | +); |
| 37 | + |
| 38 | +-- Guilds Table |
| 39 | +CREATE TABLE IF NOT EXISTS guilds ( |
| 40 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 41 | + name TEXT UNIQUE NOT NULL, |
| 42 | + description TEXT, |
| 43 | + created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| 44 | +); |
| 45 | + |
| 46 | +-- Guild Members Table |
| 47 | +CREATE TABLE IF NOT EXISTS guild_members ( |
| 48 | + guild_id INTEGER REFERENCES guilds(id) ON DELETE CASCADE, |
| 49 | + character_id INTEGER REFERENCES characters(id) ON DELETE CASCADE, |
| 50 | + rank TEXT, |
| 51 | + joined_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| 52 | + PRIMARY KEY (guild_id, character_id) |
| 53 | +); |
| 54 | + |
| 55 | +-- Inventory Table |
| 56 | +CREATE TABLE IF NOT EXISTS inventory ( |
| 57 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 58 | + character_id INTEGER REFERENCES characters(id) ON DELETE CASCADE, |
| 59 | + quantity INTEGER DEFAULT 1 |
| 60 | +); |
| 61 | + |
| 62 | +-- Items Table |
| 63 | +CREATE TABLE IF NOT EXISTS items ( |
| 64 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 65 | + name TEXT NOT NULL, |
| 66 | + rarity TEXT, |
| 67 | + flavor_text TEXT, |
| 68 | + inventory_id INTEGER REFERENCES inventory(id) ON DELETE CASCADE |
| 69 | +); |
| 70 | + |
| 71 | +-- Quests Table |
| 72 | +CREATE TABLE IF NOT EXISTS quests ( |
| 73 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 74 | + name TEXT NOT NULL, |
| 75 | + description TEXT, |
| 76 | + rewards TEXT, |
| 77 | + completed BOOLEAN DEFAULT 0, |
| 78 | + required_level INTEGER DEFAULT 1 |
| 79 | +); |
| 80 | + |
| 81 | +-- Character Quests Table |
| 82 | +CREATE TABLE IF NOT EXISTS character_quests ( |
| 83 | + character_id INTEGER REFERENCES characters(id) ON DELETE CASCADE, |
| 84 | + quest_id INTEGER REFERENCES quests(id) ON DELETE CASCADE, |
| 85 | + status TEXT DEFAULT 'In Progress', |
| 86 | + PRIMARY KEY (character_id, quest_id) |
| 87 | +); |
| 88 | + |
| 89 | +-- Random types table for testing SQLite type mappings |
| 90 | +CREATE TABLE IF NOT EXISTS random ( |
| 91 | + int1 INTEGER, |
| 92 | + real1 REAL, |
| 93 | + text1 TEXT, |
| 94 | + blob1 BLOB, |
| 95 | + numeric1 NUMERIC, |
| 96 | + bool1 BOOLEAN, |
| 97 | + date1 DATE, |
| 98 | + datetime1 DATETIME, |
| 99 | + float1 FLOAT, |
| 100 | + double1 DOUBLE, |
| 101 | + varchar1 VARCHAR(100), |
| 102 | + char1 CHAR(10), |
| 103 | + json1 JSON |
| 104 | +); |
| 105 | + |
| 106 | +--- SEED DATA |
| 107 | + |
| 108 | +INSERT INTO factions (name, description) VALUES |
| 109 | +('alliance', 'The noble and righteous faction'), |
| 110 | +('horde', 'The fierce and battle-hardened faction'); |
| 111 | + |
| 112 | +INSERT INTO races (name, faction_id) VALUES |
| 113 | +('human', 1), |
| 114 | +('night elf', 1), |
| 115 | +('dwarf', 1), |
| 116 | +('gnome', 1), |
| 117 | +('orc', 2), |
| 118 | +('troll', 2), |
| 119 | +('tauren', 2), |
| 120 | +('undead', 2); |
| 121 | + |
| 122 | +INSERT INTO classes (name, specialization) VALUES |
| 123 | +('warrior', '{"role": "tank", "weapon": "sword", "abilities": ["charge", "slam", "shield block"]}'), |
| 124 | +('hunter', '{"role": "ranged", "weapon": "bow", "abilities": ["aimed shot", "multi-shot", "trap"]}'); |
0 commit comments