Skip to main content

CREATE TABLE

BEGIN;
--
-- Create model Country
--
CREATE TABLE "webapp_country" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model Education
--
CREATE TABLE "webapp_education" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model EyeType
--
CREATE TABLE "webapp_eyetype" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model Job
--
CREATE TABLE "webapp_job" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "job_descr" text NOT NULL);
--
-- Create model JobType
--
CREATE TABLE "webapp_jobtype" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model Orientation
--
CREATE TABLE "webapp_orientation" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model Person
--
CREATE TABLE "webapp_person" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(255) NOT NULL, "last_name" varchar(255) NOT NULL, "maiden_name" varchar(255) NOT NULL, "age" integer NOT NULL, "health" integer NOT NULL, "birthday" date NOT NULL, "height" integer NOT NULL, "weight" integer NOT NULL, "body_type" varchar(255) NOT NULL, "hair_color" varchar(255) NOT NULL, "hair_length" integer NOT NULL, "eye_color" varchar(255) NOT NULL, "body_features" varchar(255) NOT NULL, "medical_edu" bool NOT NULL, "residence" varchar(255) NOT NULL, "character" text NOT NULL, "behavior_features" text NOT NULL, "psycho_features" text NOT NULL, "habits" text NOT NULL, "complexes" text NOT NULL, "weapon" text NOT NULL, "abilities" text NOT NULL, "pets" text NOT NULL, "education_id" integer NOT NULL REFERENCES "webapp_education" ("id") DEFERRABLE INITIALLY DEFERRED, "eye_type_id" integer NOT NULL REFERENCES "webapp_eyetype" ("id") DEFERRABLE INITIALLY DEFERRED, "job_id" integer NOT NULL REFERENCES "webapp_job" ("id") DEFERRABLE INITIALLY DEFERRED, "orientation_id" integer NOT NULL REFERENCES "webapp_orientation" ("id") DEFERRABLE INITIALLY DEFERRED);
--
-- Create model RelationRole
--
CREATE TABLE "webapp_relationrole" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model RelationType
--
CREATE TABLE "webapp_relationtype" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model World
--
CREATE TABLE "webapp_world" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model ZodiacSign
--
CREATE TABLE "webapp_zodiacsign" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(16) NOT NULL);
--
-- Create model Sphere
--
CREATE TABLE "webapp_sphere" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL, "country_id" integer NOT NULL REFERENCES "webapp_country" ("id") DEFERRABLE INITIALLY DEFERRED);
--
-- Create model Relations
--
CREATE TABLE "webapp_relations" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "person_first_id" integer NOT NULL REFERENCES "webapp_person" ("id") DEFERRABLE INITIALLY DEFERRED, "person_first_role_id" integer NOT NULL REFERENCES "webapp_relationrole" ("id") DEFERRABLE INITIALLY DEFERRED, "person_second_id" integer NOT NULL REFERENCES "webapp_person" ("id") DEFERRABLE INITIALLY DEFERRED, "person_second_role_id" integer NOT NULL REFERENCES "webapp_relationrole" ("id") DEFERRABLE INITIALLY DEFERRED, "rel_type_id" integer NOT NULL REFERENCES "webapp_relationtype" ("id") DEFERRABLE INITIALLY DEFERRED);
--
-- Add field sphere to person
--
CREATE TABLE "new__webapp_person" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(255) NOT NULL, "last_name" varchar(255) NOT NULL, "maiden_name" varchar(255) NOT NULL, "age" integer NOT NULL, "health" integer NOT NULL, "birthday" date NOT NULL, "height" integer NOT NULL, "weight" integer NOT NULL, "body_type" varchar(255) NOT NULL, "hair_color" varchar(255) NOT NULL, "hair_length" integer NOT NULL, "eye_color" varchar(255) NOT NULL, "body_features" varchar(255) NOT NULL, "medical_edu" bool NOT NULL, "residence" varchar(255) NOT NULL, "character" text NOT NULL, "behavior_features" text NOT NULL, "psycho_features" text NOT NULL, "habits" text NOT NULL, "complexes" text NOT NULL, "weapon" text NOT NULL, "abilities" text NOT NULL, "pets" text NOT NULL, "education_id" integer NOT NULL REFERENCES "webapp_education" ("id") DEFERRABLE INITIALLY DEFERRED, "eye_type_id" integer NOT NULL REFERENCES "webapp_eyetype" ("id") DEFERRABLE INITIALLY DEFERRED, "job_id" integer NOT NULL REFERENCES "webapp_job" ("id") DEFERRABLE INITIALLY DEFERRED, "orientation_id" integer NOT NULL REFERENCES "webapp_orientation" ("id") DEFERRABLE INITIALLY DEFERRED, "sphere_id" integer NOT NULL REFERENCES "webapp_sphere" ("id") DEFERRABLE INITIALLY DEFERRED);
INSERT INTO "new__webapp_person" ("id", "first_name", "last_name", "maiden_name", "age", "health", "birthday", "height", "weight", "body_type", "hair_color", "hair_length", "eye_color", "body_features", "medical_edu", "residence", "character", "behavior_features", "psycho_features", "habits", "complexes", "weapon", "abilities", "pets", "education_id", "eye_type_id", "job_id", "orientation_id", "sphere_id") SELECT "id", "first_name", "last_name", "maiden_name", "age", "health", "birthday", "height", "weight", "body_type", "hair_color", "hair_length", "eye_color", "body_features", "medical_edu", "residence", "character", "behavior_features", "psycho_features", "habits", "complexes", "weapon", "abilities", "pets", "education_id", "eye_type_id", "job_id", "orientation_id", NULL FROM "webapp_person";
DROP TABLE "webapp_person";
ALTER TABLE "new__webapp_person" RENAME TO "webapp_person";
CREATE INDEX "webapp_sphere_country_id_3774d271" ON "webapp_sphere" ("country_id");
CREATE INDEX "webapp_relations_person_first_id_e12e1ad4" ON "webapp_relations" ("person_first_id");
CREATE INDEX "webapp_relations_person_first_role_id_7fa1b811" ON "webapp_relations" ("person_first_role_id");
CREATE INDEX "webapp_relations_person_second_id_876aa37f" ON "webapp_relations" ("person_second_id");
CREATE INDEX "webapp_relations_person_second_role_id_00f12786" ON "webapp_relations" ("person_second_role_id");
CREATE INDEX "webapp_relations_rel_type_id_efb339ea" ON "webapp_relations" ("rel_type_id");
CREATE INDEX "webapp_person_education_id_87d28545" ON "webapp_person" ("education_id");
CREATE INDEX "webapp_person_eye_type_id_1e0b79a1" ON "webapp_person" ("eye_type_id");
CREATE INDEX "webapp_person_job_id_7127d6dd" ON "webapp_person" ("job_id");
CREATE INDEX "webapp_person_orientation_id_a736882f" ON "webapp_person" ("orientation_id");
CREATE INDEX "webapp_person_sphere_id_fd2710ee" ON "webapp_person" ("sphere_id");
--
-- Add field zodiac to person
--
CREATE TABLE "new__webapp_person" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(255) NOT NULL, "last_name" varchar(255) NOT NULL, "maiden_name" varchar(255) NOT NULL, "age" integer NOT NULL, "health" integer NOT NULL, "birthday" date NOT NULL, "height" integer NOT NULL, "weight" integer NOT NULL, "body_type" varchar(255) NOT NULL, "hair_color" varchar(255) NOT NULL, "hair_length" integer NOT NULL, "eye_color" varchar(255) NOT NULL, "body_features" varchar(255) NOT NULL, "medical_edu" bool NOT NULL, "residence" varchar(255) NOT NULL, "character" text NOT NULL, "behavior_features" text NOT NULL, "psycho_features" text NOT NULL, "habits" text NOT NULL, "complexes" text NOT NULL, "weapon" text NOT NULL, "abilities" text NOT NULL, "pets" text NOT NULL, "education_id" integer NOT NULL REFERENCES "webapp_education" ("id") DEFERRABLE INITIALLY DEFERRED, "eye_type_id" integer NOT NULL REFERENCES "webapp_eyetype" ("id") DEFERRABLE INITIALLY DEFERRED, "job_id" integer NOT NULL REFERENCES "webapp_job" ("id") DEFERRABLE INITIALLY DEFERRED, "orientation_id" integer NOT NULL REFERENCES "webapp_orientation" ("id") DEFERRABLE INITIALLY DEFERRED, "sphere_id" integer NOT NULL REFERENCES "webapp_sphere" ("id") DEFERRABLE INITIALLY DEFERRED, "zodiac_id" integer NOT NULL REFERENCES "webapp_zodiacsign" ("id") DEFERRABLE INITIALLY DEFERRED);
INSERT INTO "new__webapp_person" ("id", "first_name", "last_name", "maiden_name", "age", "health", "birthday", "height", "weight", "body_type", "hair_color", "hair_length", "eye_color", "body_features", "medical_edu", "residence", "character", "behavior_features", "psycho_features", "habits", "complexes", "weapon", "abilities", "pets", "education_id", "eye_type_id", "job_id", "orientation_id", "sphere_id", "zodiac_id") SELECT "id", "first_name", "last_name", "maiden_name", "age", "health", "birthday", "height", "weight", "body_type", "hair_color", "hair_length", "eye_color", "body_features", "medical_edu", "residence", "character", "behavior_features", "psycho_features", "habits", "complexes", "weapon", "abilities", "pets", "education_id", "eye_type_id", "job_id", "orientation_id", "sphere_id", NULL FROM "webapp_person";
DROP TABLE "webapp_person";
ALTER TABLE "new__webapp_person" RENAME TO "webapp_person";
CREATE INDEX "webapp_person_education_id_87d28545" ON "webapp_person" ("education_id");
CREATE INDEX "webapp_person_eye_type_id_1e0b79a1" ON "webapp_person" ("eye_type_id");
CREATE INDEX "webapp_person_job_id_7127d6dd" ON "webapp_person" ("job_id");
CREATE INDEX "webapp_person_orientation_id_a736882f" ON "webapp_person" ("orientation_id");
CREATE INDEX "webapp_person_sphere_id_fd2710ee" ON "webapp_person" ("sphere_id");
CREATE INDEX "webapp_person_zodiac_id_ff8e1f59" ON "webapp_person" ("zodiac_id");
--
-- Add field job_type to job
--
CREATE TABLE "new__webapp_job" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "job_descr" text NOT NULL, "job_type_id" integer NOT NULL REFERENCES "webapp_jobtype" ("id") DEFERRABLE INITIALLY DEFERRED);
INSERT INTO "new__webapp_job" ("id", "job_descr", "job_type_id") SELECT "id", "job_descr", NULL FROM "webapp_job";
DROP TABLE "webapp_job";
ALTER TABLE "new__webapp_job" RENAME TO "webapp_job";
CREATE INDEX "webapp_job_job_type_id_eb0c0d06" ON "webapp_job" ("job_type_id");
--
-- Add field ruler to country
--
CREATE TABLE "new__webapp_country" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL, "ruler_id" integer NOT NULL REFERENCES "webapp_person" ("id") DEFERRABLE INITIALLY DEFERRED);
INSERT INTO "new__webapp_country" ("id", "name", "ruler_id") SELECT "id", "name", NULL FROM "webapp_country";
DROP TABLE "webapp_country";
ALTER TABLE "new__webapp_country" RENAME TO "webapp_country";
CREATE INDEX "webapp_country_ruler_id_f0c0ea07" ON "webapp_country" ("ruler_id");
--
-- Add field world to country
--
CREATE TABLE "new__webapp_country" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL, "ruler_id" integer NOT NULL REFERENCES "webapp_person" ("id") DEFERRABLE INITIALLY DEFERRED, "world_id" integer NOT NULL REFERENCES "webapp_world" ("id") DEFERRABLE INITIALLY DEFERRED);
INSERT INTO "new__webapp_country" ("id", "name", "ruler_id", "world_id") SELECT "id", "name", "ruler_id", NULL FROM "webapp_country";
DROP TABLE "webapp_country";
ALTER TABLE "new__webapp_country" RENAME TO "webapp_country";
CREATE INDEX "webapp_country_ruler_id_f0c0ea07" ON "webapp_country" ("ruler_id");
CREATE INDEX "webapp_country_world_id_6d5818db" ON "webapp_country" ("world_id");
COMMIT;