 START TRANSACTION;
 
 CREATE TABLE "risk_groups" (
-	"id" SERIAL PRIMARY KEY,
-	"name" varchar(255)
+	"id" BIGSERIAL PRIMARY KEY,
+	"name" varchar(255) UNIQUE
 );
 
 -- CREATE UNIQUE INDEX uix_risk_groups_name ON "risk_groups"("name");
 
 CREATE TABLE "replica_sets" (
-	"id" SERIAL PRIMARY KEY,
-	"name" varchar(255),
+	"id" BIGSERIAL PRIMARY KEY,
+	"name" varchar(255) UNIQUE,
 	"persistent_member_count" integer,
 	"volatile_member_count" integer,
 	"configure_as_sharding_config_server" bool

-- CREATE UNIQUE INDEX uix_replica_sets_name ON "replica_sets"("name");

CREATE TABLE "msp_errors" (
	"id" SERIAL PRIMARY KEY,
	"identifier" varchar(255),
	"description" varchar(255),
	"long_description" varchar(255)
);

CREATE TABLE slaves (
	"id" SERIAL PRIMARY KEY,
	"hostname" varchar(255),
	"port" integer,
	"mongod_port_range_begin" integer,
	"mongod_port_range_end" integer,

ALTER TABLE mongod_states ADD CONSTRAINT constr_parent_mongod FOREIGN KEY (parent_mongod_id) REFERENCES mongods(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

CREATE TABLE "replica_set_members" ( -- TODO is this even used?
	"id" BIGSERIAL PRIMARY KEY,
	"hostname" varchar(255),
	"port" integer,
	"mongod_state_id" integer REFERENCES mongod_states(id) DEFERRABLE INITIALLY DEFERRED
);

CREATE TABLE "problems" (
	"id" BIGSERIAL PRIMARY KEY,
	"description" varchar(255),
	"long_description" varchar(255),
	"problem_type" integer,
