Commit 418be2aa authored by jan.koester's avatar jan.koester
Browse files

optimize sql

parent 97b3a633
Loading
Loading
Loading
Loading
+9 −17
Original line number Diff line number Diff line
@@ -627,36 +627,28 @@ namespace blogi {
        void initPlugin(){
            blogi::SQL sql;
            blogi::DBResult res;
            sql << "CREATE TABLE public.content ("
            sql << "CREATE TABLE IF NOT EXISTS public.content ("
                <<     "id serial NOT NULL PRIMARY KEY,"
                <<     "title character varying(255) NOT NULL,"
                <<     "text text NOT NULL,"
                <<     "descrition character varying(255) NOT NULL,"
                <<     "author integer ,"
                <<     "created date NOT NULL"
                <<     "created date NOT NULL,"
                <<     "FOREIGN KEY (author) REFERENCES public.users(id)"
                <<   "); "
                <<   "ADD CONSTRAINT fk_author FOREIGN KEY (author) REFERENCES public.users(id); "
                << "CREATE TABLE IF NOT EXISTS public.tags ("
                <<      "id serial NOT NULL,"
                <<      "name character varying(255) NOT NULL,"
                <<      "CONSTRAINT tags_pkey PRIMARY KEY (id),"
                <<      "CONSTRAINT name_unique UNIQUE (name)"
                <<      "id serial NOT NULL PRIMARY KEY,"
                <<      "name character varying(255) NOT NULL UNIQUE"
                << "); "
                << "CREATE TABLE IF NOT EXISTS public.tags("
                <<   "id serial NOT NULL PRIMARY KEY,"
                <<   "name character varying(255) NOT NULL UNIQUE,"
                <<   "name character varying(255) NOT NULL UNIQUE"
                << "); "
                << "CREATE TABLE IF NOT EXISTS public.tags_content ("
                <<   "tag_id integer NOT NULL,"
                <<   "content_id integer NOT NULL,"
                <<   "CONSTRAINT tags_content_content_id_fkey FOREIGN KEY (content_id)"
                <<     "REFERENCES public.content (id) MATCH SIMPLE"
                <<     "ON UPDATE NO ACTION"
                <<     "ON DELETE NO ACTION,"
                <<   "CONSTRAINT tags_content_tag_id_fkey FOREIGN KEY (tag_id)"
                <<     "REFERENCES public.tags (id) MATCH SIMPLE"
                <<     "ON UPDATE NO ACTION"
                <<     "ON DELETE NO ACTION"
                <<   "FOREIGN KEY (content_id) REFERENCES public.content (id),"
                <<   "FOREIGN KEY (tag_id) REFERENCES public.tags (id)"
                << ");";
            Args->database->exec(&sql,res);
            return;