48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package db
|
|
|
|
var migrations = []string{
|
|
// 0: accounts table
|
|
`CREATE TABLE IF NOT EXISTS accounts (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
username VARCHAR(32) UNIQUE NOT NULL,
|
|
password VARCHAR(128) NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
)`,
|
|
|
|
// 1: characters table
|
|
`CREATE TABLE IF NOT EXISTS characters (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
account_id BIGINT NOT NULL REFERENCES accounts(id),
|
|
name VARCHAR(32) UNIQUE NOT NULL,
|
|
level INT NOT NULL DEFAULT 1,
|
|
exp BIGINT NOT NULL DEFAULT 0,
|
|
hp INT NOT NULL DEFAULT 100,
|
|
max_hp INT NOT NULL DEFAULT 100,
|
|
mp INT NOT NULL DEFAULT 50,
|
|
max_mp INT NOT NULL DEFAULT 50,
|
|
str INT NOT NULL DEFAULT 10,
|
|
dex INT NOT NULL DEFAULT 10,
|
|
int_stat INT NOT NULL DEFAULT 10,
|
|
zone_id INT NOT NULL DEFAULT 1,
|
|
pos_x REAL NOT NULL DEFAULT 0,
|
|
pos_y REAL NOT NULL DEFAULT 0,
|
|
pos_z REAL NOT NULL DEFAULT 0,
|
|
rotation REAL NOT NULL DEFAULT 0,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
)`,
|
|
|
|
// 2: inventory table
|
|
`CREATE TABLE IF NOT EXISTS inventory (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
character_id BIGINT NOT NULL REFERENCES characters(id) ON DELETE CASCADE,
|
|
slot INT NOT NULL,
|
|
item_id INT NOT NULL,
|
|
quantity INT NOT NULL DEFAULT 1,
|
|
UNIQUE(character_id, slot)
|
|
)`,
|
|
|
|
// 3: index for character lookups by account
|
|
`CREATE INDEX IF NOT EXISTS idx_characters_account_id ON characters(account_id)`,
|
|
}
|