   CONSTRAINT "posmatchid_fk" FOREIGN KEY ("posmatchid") REFERENCES "posmatchids" ("posmatchid") ON DELETE SET NULL ON UPDATE NO ACTION,
   CONSTRAINT "username_fk" FOREIGN KEY ("username") REFERENCES "users" ("username") ON DELETE NO ACTION ON UPDATE NO ACTION
 );
-create index "posmatchid_fk_idx" on "comments"("posmatchid");
-create index "parentid_idx" on "comments"("parentid");
-create index "username_fk_idx" on "comments"("username");
+create index if not exists "posmatchid_fk_idx" on "comments"("posmatchid");
+create index if not exists "parentid_idx" on "comments"("parentid");
+create index if not exists "username_fk_idx" on "comments"("username");
 
-CREATE TABLE "posmatchids" (
+CREATE TABLE if not exists "posmatchids"(
   "id" integer primary key,
   "posmatchid" char(27) NOT NULL,
   "decisiontype" char(1) DEFAULT NULL,

  "submissions" int(11) DEFAULT NULL,
  UNIQUE ("posmatchid")
);
create index "posmatchids_new_gnuid_idx" on "posmatchids"("decisiontype","version","rating");

CREATE TABLE "postags" (
  "id" integer primary key,
  "POSMATCHID" char(27) NOT NULL,
  "TAG" varchar(30) NOT NULL,

  CONSTRAINT "usersposmatchids_ibfk_1" FOREIGN KEY ("username") REFERENCES "users" ("username"),
  CONSTRAINT "usersposmatchids_ibfk_2" FOREIGN KEY ("posmatchid") REFERENCES "posmatchids" ("posmatchid") ON DELETE CASCADE
);
create index if not exists "usersposmatchids_idx1" on "usersposmatchids"("eqdiff");
create index if not exists "username" on "usersposmatchids"("username");
