

CREATE TABLE IF NOT EXISTS organization (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name char(255) NOT NULL UNIQUE KEY,
    admin bigint(20) UNSIGNED DEFAULT NULL UNIQUE KEY,
    FOREIGN KEY (admin) REFERENCES user (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

INSERT INTO organization (name) values ('Tallinna Ülikool');
INSERT INTO organization (name) values ('Tallinna Tehnikaülikool');
INSERT INTO organization (name) values ('Tartu Ülikool');
INSERT INTO organization (name) values ('Maaülikool');
INSERT INTO organization (name) values ('Haapsalu Kolledzh');

CREATE TABLE IF NOT EXISTS user_organization (
    user bigint(20) UNSIGNED NOT NULL,
    organization bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (user) REFERENCES user (id) ON DELETE CASCADE,
    FOREIGN KEY (organization) REFERENCES organization (id) ON DELETE CASCADE,
    PRIMARY KEY (user, organization)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS dictionary (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    word char(255) NOT NULL,
    category char(255) NOT NULL,
    language char(2) DEFAULT 'et',
    organization bigint(20) UNSIGNED DEFAULT NULL,
    selected boolean DEFAULT false,
    FOREIGN KEY (organization) REFERENCES organization (id) ON DELETE CASCADE,
    UNIQUE KEY word_org(word, organization)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

INSERT INTO dictionary (word, category, language, organization, selected) values ('Ajaloo Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Eesti Demograafia Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Eesti Humanitaarinstituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Eesti Keele ja Kultuuri Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Eesti Tuleviku-uuringute Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Germaani-Romaani Keelte ja Kultuuride Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Informaatika Instituut', 'provider', 'et', 1, 1);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Infoteaduste Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Kasvatusteaduste Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Kommunikatsiooni Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Kunstide Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Matemaatika ja Loodusteaduste Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Psühholoogia Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Rahvusvaheliste ja Sotsiaaluuringute Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Riigiteaduste Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Slaavi Keelte ja Kultuuride Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Sotsiaaltöö Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Terviseteaduste ja Spordi Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Ökoloogia Instituut', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Balti Filmi- ja Meediakool', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Haapsalu Kolledž', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Katariina Kolledž', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Rakvere Kolledž', 'provider', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Õigusakadeemia', 'provider', 'et', 1, 0);

INSERT INTO dictionary (word, category, language, organization, selected) values ('Bachelor', 'educationallevel', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Master', 'educationallevel', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Doctoral', 'educationallevel', 'et', 1, 0);

INSERT INTO dictionary (word, category, language, organization, selected) values ('Estonian', 'languageofinstructions', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('English', 'languageofinstructions', 'et', 1, 0);
INSERT INTO dictionary (word, category, language, organization, selected) values ('Russian', 'languageofinstructions', 'et', 1, 0);

CREATE TABLE IF NOT EXISTS dictionary_entry (
    dictionary bigint(20) UNSIGNED NOT NULL,
    word char(255) NOT NULL,
    language char(2) DEFAULT 'et',
    FOREIGN KEY (dictionary) REFERENCES dictionary (id) ON DELETE CASCADE,
    PRIMARY KEY (dictionary, word, language)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS image (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    image LONGBLOB,
    name char(255) NOT NULL,
    filetype char(30),
    filesize int(8),
    creator bigint(20) UNSIGNED,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    trashed boolean DEFAULT false,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS course (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    title char(255) NOT NULL,
    identifier char(255),
    credits int(5),
    provider bigint(20) UNSIGNED DEFAULT NULL,
    educationlevel bigint(20) UNSIGNED DEFAULT NULL,
    languageofinstruction bigint(20) UNSIGNED DEFAULT NULL,
    objective TEXT,
    description TEXT,
    assessment TEXT,
    prerequisite TEXT,
    tag char(255),
    start int(11),
    end int(11),
    closes int(11),
    attendancemode enum('0','1','2','3','4','5','6') DEFAULT '0',
    permission enum('0','1','2') DEFAULT '0',
    enrollment enum('0','1','2') DEFAULT '0',
    status enum('0','1','2') DEFAULT '0',
    image bigint(20) UNSIGNED DEFAULT NULL,
    owner bigint(20) UNSIGNED,
    creator bigint(20) UNSIGNED,
    organization bigint(20) UNSIGNED,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    approved boolean NOT NULL DEFAULT 0,
    trashed boolean NOT NULL DEFAULT 0,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE NO ACTION,
    FOREIGN KEY (owner) REFERENCES user (id) ON DELETE CASCADE,
    FOREIGN KEY (organization) REFERENCES organization (id) ON DELETE SET NULL,
    FOREIGN KEY (provider) REFERENCES dictionary (id) ON DELETE SET NULL,
    FOREIGN KEY (educationlevel) REFERENCES dictionary (id) ON DELETE SET NULL,
    FOREIGN KEY (languageofinstruction) REFERENCES dictionary (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS facilitator (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    facilitator bigint(20) UNSIGNED NOT NULL,
    status int(1) NOT NULL DEFAULT 0,
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (facilitator) REFERENCES user (id) ON DELETE CASCADE,
    UNIQUE KEY course_facilitator (course, facilitator) 
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS learner (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL DEFAULT 0,
    learner bigint(20) UNSIGNED NOT NULL DEFAULT 0,
    status int(1) NOT NULL DEFAULT 0,
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (learner) REFERENCES user (id) ON DELETE CASCADE,
    UNIQUE KEY course_learner (course, learner)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS profile (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    user_id bigint(20) UNSIGNED NOT NULL,
    description TEXT,
    homepage char(255),
    twitter char(255),
    delicious char(255),
    mendeley char(255),
    skype char(255),
    msn char(255),
    blogurl varchar(255) DEFAULT '',
    department bigint(20) UNSIGNED DEFAULT NULL,
    FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
    FOREIGN KEY (department) REFERENCES dictionary (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS courseblog_post (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    title char(255),
    body TEXT,
    creator bigint(20) UNSIGNED NOT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    hidden boolean NOT NULL DEFAULT 0,
    type varchar(20) DEFAULT "CourseblogPost",
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS courseblog_comment (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    courseblog_post bigint(20) UNSIGNED NOT NULL,
    title char(255),
    body TEXT,
    creator bigint(20) UNSIGNED NOT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    hidden boolean NOT NULL DEFAULT 0,
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (courseblog_post) REFERENCES courseblog_post (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS coursegroup (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    title char(255),
    description TEXT,
    workspace char(255),
    creator bigint(20) UNSIGNED NOT NULL,
    created TIMESTAMP DEFAULT NOW(),
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS coursegroup_member (
    coursegroup bigint(20) UNSIGNED NOT NULL,
    learner bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (coursegroup) REFERENCES coursegroup (id) ON DELETE CASCADE,
    FOREIGN KEY (learner) REFERENCES learner (id) ON DELETE CASCADE,
    PRIMARY KEY (coursegroup, learner)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS tag (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name char(255),
    slug char(255),
    count int(11)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS tag_relationship (
    parent_id bigint(20) UNSIGNED NOT NULL,
    parent_type varchar(20) NOT NULL,
    tag_id bigint(20) UNSIGNED NOT NULL,
    org_id bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE,
    FOREIGN KEY (org_id) REFERENCES organization (id) ON DELETE CASCADE,
    PRIMARY KEY (parent_id, parent_type, tag_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS category (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name char(255),
    slug char(255),
    parent bigint(20) UNSIGNED DEFAULT NULL,
    course bigint(20) UNSIGNED NOT NULL,
    count int(11),
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (parent) REFERENCES category (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS category_relationship (
    parent_id bigint(20) UNSIGNED NOT NULL,
    parent_type varchar(20) NOT NULL,
    category_id bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE,
    PRIMARY KEY (parent_id, parent_type, category_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS assignment (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    title char(255) NOT NULL,
    description TEXT NOT NULL,
    structure TEXT,
    maxpoints int(4) DEFAULT 0,
    start int(11) NOT NULL,
    end int(11) NOT NULL,
    creator bigint(20) UNSIGNED,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    late_submission boolean NOT NULL DEFAULT 0,
    submission_visibility boolean NOT NULL DEFAULT 0,
    type varchar(20) DEFAULT "Assignment",
    subtype char(255) NOT NULL,
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS assignment_target_group (
    assignment_id bigint(20) UNSIGNED NOT NULL,
    coursegroup_id bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (assignment_id) REFERENCES assignment (id) ON DELETE CASCADE,
    FOREIGN KEY (coursegroup_id) REFERENCES coursegroup (id) ON DELETE CASCADE,
    PRIMARY KEY (assignment_id, coursegroup_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    assignment bigint(20) UNSIGNED NOT NULL,
    url char(255) NOT NULL,
    title char(255) DEFAULT NULL,
    content TEXT NOT NULL,
    backup TEXT DEFAULT NULL,
    creator bigint(20) UNSIGNED,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    graded TIMESTAMP,
    grade int(3) DEFAULT NULL,
    feedback TEXT DEFAULT NULL,
    FOREIGN KEY (assignment) REFERENCES assignment (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS resource_folder (
	id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
	title char(255) NOT NULL,
    position int(5) NOT NULL,
	creator bigint(20) UNSIGNED NOT NULL,
	parent bigint(20) UNSIGNED,
	course bigint(20) UNSIGNED NOT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
	FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE,
	FOREIGN KEY (parent) REFERENCES resource_folder (id) ON DELETE CASCADE,
	FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE	
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS learning_resource (
	id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
	title char(255) NOT NULL,
	description TEXT,
	subtype char(100),
	url char(255),
	author char(100),
	creator bigint(20) UNSIGNED NOT NULL,
	licence char(255),
	created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    published int(11),
	position int(5) NOT NULL,
	course bigint(20) UNSIGNED NOT NULL,
	folder bigint(20) UNSIGNED,
    type varchar(20) DEFAULT "LearningResource",
	FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
	FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE,
	FOREIGN KEY (folder) REFERENCES resource_folder (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS learning_outcome (
	id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
	title TEXT,
	creator bigint(20) UNSIGNED NOT NULL,
	created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
	course bigint(20) UNSIGNED NOT NULL,
	type varchar(20) DEFAULT "LearningOutcome",
	FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
	FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS assignment_learning_outcomes (
    assignment bigint(20) UNSIGNED NOT NULL,
    learningoutcome bigint(20) UNSIGNED NOT NULL,
    FOREIGN KEY (assignment) REFERENCES assignment (id) ON DELETE CASCADE,
    FOREIGN KEY (learningoutcome) REFERENCES learning_outcome (id) ON DELETE CASCADE,
    PRIMARY KEY (assignment, learningoutcome)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS blogpost (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED NOT NULL,
    url char(255) NOT NULL,
    title char(255) DEFAULT NULL,
    content TEXT NOT NULL,
    creator bigint(20) UNSIGNED,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS activity (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    course bigint(20) UNSIGNED DEFAULT NULL,
    course_title char(255),
    event char(255),
    object_id bigint(20) UNSIGNED DEFAULT NULL,
    object_title char(255),
    object_type char(20),
    creator bigint(20) UNSIGNED DEFAULT NULL,
    creator_fullname char(255),
    created TIMESTAMP DEFAULT NOW(),
    FOREIGN KEY (course) REFERENCES course (id) ON DELETE SET NULL,
    FOREIGN KEY (creator) REFERENCES user (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS grade (
    learner_id bigint(20) UNSIGNED NOT NULL,
    grade varchar(10) NOT NULL DEFAULT '',
    feedback varchar(255) NOT NULL DEFAULT '',
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    FOREIGN KEY (learner_id) REFERENCES learner (id) ON DELETE CASCADE,
    PRIMARY KEY (learner_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE id_gen (
    ID_NAME VARCHAR(80),
    ID_VAL BIGINT UNSIGNED,
    CONSTRAINT pk_id_name PRIMARY KEY(ID_NAME)
);

INSERT INTO id_gen (id_name, id_val) VALUES("LAST_ASSIGNMENT", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_ANSWER", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_ACTIVITY", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_CATEGORY", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_CLIENT", 1);

INSERT INTO id_gen (id_name, id_val) VALUES("LAST_COURSE", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_COURSE_BLOGPOST_COMMENT", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_COURSE_BLOGPOST", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_COURSE_GROUP", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_FACILITATOR", 1);

INSERT INTO id_gen (id_name, id_val) VALUES("LAST_IMAGE", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_LEARNER", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_LEARNING_OUTCOME", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_LEARNING_RESOURCE", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_ORGANIZATION", 1);

INSERT INTO id_gen (id_name, id_val) VALUES("LAST_PROFILE", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_RESOURCE_FOLDER", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_TAG", 1);
INSERT INTO id_gen (id_name, id_val) VALUES("LAST_USER_ID", 1);