ALTER TYPE governments RENAME TO govs;
\i tables/races.sql
\i data/races.sql
\i tables/governments.sql
\i data/governments.sql

DROP VIEW full_defcalls;
DROP VIEW defcalls;
DROP VIEW full_intel;
DROP VIEW users_defprio;
DROP VIEW alliance_resources;
DROP VIEW current_planet_stats_full;
DROP VIEW current_planet_stats;
ALTER TABLE planets
	ALTER COLUMN race TYPE TEXT,
	ALTER COLUMN gov TYPE TEXT,
	ALTER COLUMN gov SET DEFAULT '';
ALTER TABLE planets ADD FOREIGN KEY (race) REFERENCES races(race) ON UPDATE CASCADE ON DELETE RESTRICT;
ALTER TABLE planets ADD FOREIGN KEY (gov) REFERENCES governments(gov) ON UPDATE CASCADE ON DELETE SET DEFAULT;
\d planets
\i views/current_planet_stats.sql
\i views/alliances_resources.sql
\i views/users_defprio.sql
\i views/full_intel.sql
\i views/defcalls.sql

DROP FUNCTION IF EXISTS find_planet_id(text,text,text,race);
DROP FUNCTION covop_alert(integer, integer, integer, integer, govs, integer);
\i functions/find_planet_id.sql
\i functions/covop_alert.sql
ALTER TABLE ship_stats ADD FOREIGN KEY (race) REFERENCES races(race) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ship_stats ADD COLUMN cloaked BOOLEAN NOT NULL DEFAULT false, ADD COLUMN baseeta INTEGER NOT NULL DEFAULT 0;
ALTER TABLE ship_stats ALTER COLUMN cloaked DROP DEFAULT, ALTER COLUMN baseeta DROP DEFAULT, ALTER COLUMN guns DROP DEFAULT, ALTER COLUMN eres DROP DEFAULT;
\d ship_stats

DROP TYPE race;
DROP TYPE govs;

ALTER TABLE incomings DROP CONSTRAINT incomings_call_key, ADD CONSTRAINT incomings_unique_key UNIQUE (call, pid, fleet, eta);

\i functions/hostile_alliances.sql
