-- LegacyWorlds Beta 6
-- PostgreSQL database scripts
--
-- Translations
--
-- Copyright(C) 2004-2010, DeepClone Development
-- --------------------------------------------------------

--
-- Languages
--
CREATE TABLE defs.languages(
	id					SERIAL PRIMARY KEY ,
	language			VARCHAR(5) NOT NULL ,
	name				VARCHAR(48) NOT NULL
);

CREATE UNIQUE INDEX idx_languages_lid
	ON defs.languages (language);



--
-- Internationalised strings
--
CREATE TABLE defs.strings(
	id					SERIAL PRIMARY KEY ,
	name				VARCHAR(64) NOT NULL
);

CREATE UNIQUE INDEX idx_strings_id
	ON defs.strings (name);



--
-- Translations
--
CREATE TABLE defs.translations(
	lang_id				INT NOT NULL ,
	string_id			INT NOT NULL ,
	translated_string	TEXT NOT NULL ,
	PRIMARY KEY (lang_id, string_id)
);

CREATE INDEX idx_translations_string
	ON defs.translations (string_id);

ALTER TABLE defs.translations
	ADD CONSTRAINT fk_translation_language
		FOREIGN KEY (lang_id) REFERENCES defs.languages ,
	ADD CONSTRAINT fk_translation_string
		FOREIGN KEY (string_id) REFERENCES defs.strings;
