-- CreateEnum
CREATE TYPE "VerificationLevel" AS ENUM ('BASIC', 'ADVANCED', 'ELITE');

-- CreateEnum
CREATE TYPE "Role" AS ENUM ('ADMIN', 'EDITOR', 'USER');

-- CreateEnum
CREATE TYPE "UserStatus" AS ENUM ('ACTIVE', 'PENDING', 'BLOCKED', 'REJECTED');

-- CreateEnum
CREATE TYPE "PointsType" AS ENUM ('GOOD', 'EVIL');

-- CreateEnum
CREATE TYPE "RitualType" AS ENUM ('BONFIRE', 'SUN');

-- CreateEnum
CREATE TYPE "AiStatus" AS ENUM ('NONE', 'PENDING', 'VERIFIED', 'REJECTED');

-- CreateTable
CREATE TABLE "users" (
    "id" SERIAL NOT NULL,
    "login" TEXT NOT NULL,
    "passwordHash" TEXT NOT NULL,
    "role" "Role" NOT NULL DEFAULT 'USER',
    "status" "UserStatus" NOT NULL DEFAULT 'PENDING',
    "avatarUrl" TEXT,
    "note" TEXT NOT NULL,
    "votes_pos" INTEGER NOT NULL DEFAULT 0,
    "votes_neg" INTEGER NOT NULL DEFAULT 0,
    "balance_updated_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
    "email" TEXT,
    "phone" TEXT,
    "verificationLvl" DOUBLE PRECISION NOT NULL DEFAULT 0.1,
    "country_id" INTEGER,
    "timezone_id" INTEGER,
    "location_updated_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
    "lastActiveAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "currentWeight" DOUBLE PRECISION NOT NULL DEFAULT 1.0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "last_achievement_id" INTEGER,
    "streak_length_days" INTEGER NOT NULL DEFAULT 0,
    "last_bonfire_vote_at" TIMESTAMP(3),
    "last_sun_vote_at" TIMESTAMP(3),

    CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "auth_tokens" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "tokenHash" TEXT NOT NULL,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "revokedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "auth_tokens_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "votes" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "target_country_id" INTEGER NOT NULL,
    "pointsType" "PointsType" NOT NULL,
    "basePoints" INTEGER NOT NULL,
    "finalWeight" DOUBLE PRECISION NOT NULL,
    "newsUrl" TEXT,
    "ritual_type" "RitualType",
    "aiStatus" "AiStatus" NOT NULL DEFAULT 'NONE',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "votes_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_daily_status" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "lastActiveAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "currentPotential" DOUBLE PRECISION NOT NULL DEFAULT 0.0,

    CONSTRAINT "user_daily_status_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "countries" (
    "id" SERIAL NOT NULL,
    "isoCode" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "population" BIGINT,
    "landArea" DOUBLE PRECISION,
    "totalGoodPoints" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "totalEvilPoints" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "voiceOfNation" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "neglectIndex" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "countries_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "timezones" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,

    CONSTRAINT "timezones_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "achievement_categories" (
    "id" SERIAL NOT NULL,
    "slug" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "sort_order" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "achievement_categories_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "achievements" (
    "id" SERIAL NOT NULL,
    "code" TEXT NOT NULL,
    "category_id" INTEGER NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "trigger" TEXT,
    "trigger_window" TEXT,
    "sort_order" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "achievements_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_achievement_stats" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "activity_streak_days" INTEGER NOT NULL DEFAULT 0,
    "last_active_date" TIMESTAMP(3),
    "total_votes" INTEGER NOT NULL DEFAULT 0,
    "positive_votes_count" INTEGER NOT NULL DEFAULT 0,
    "negative_votes_count" INTEGER NOT NULL DEFAULT 0,
    "unique_countries_7d" INTEGER NOT NULL DEFAULT 0,
    "unique_countries_30d" INTEGER NOT NULL DEFAULT 0,
    "verified_votes_30d" INTEGER NOT NULL DEFAULT 0,
    "total_votes_30d" INTEGER NOT NULL DEFAULT 0,
    "ritual_streak_days" INTEGER NOT NULL DEFAULT 0,
    "last_ritual_at" TIMESTAMP(3),
    "sun_rituals_30d" INTEGER NOT NULL DEFAULT 0,
    "bonfire_rituals_30d" INTEGER NOT NULL DEFAULT 0,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "user_achievement_stats_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "aggregation_watermarks" (
    "id" BIGSERIAL NOT NULL,
    "job_name" VARCHAR(64) NOT NULL,
    "period_start_utc" TIMESTAMP(3) NOT NULL,
    "last_vote_id" BIGINT NOT NULL,
    "last_created_at" TIMESTAMP(3),
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "aggregation_watermarks_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_index_hourly" (
    "id" BIGSERIAL NOT NULL,
    "country_id" INTEGER NOT NULL,
    "hour_utc" TIMESTAMP(3) NOT NULL,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "ei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "good_vote_count" INTEGER NOT NULL DEFAULT 0,
    "evil_vote_count" INTEGER NOT NULL DEFAULT 0,
    "distinct_voter_count" INTEGER,
    "von" DOUBLE PRECISION,
    "ni" DOUBLE PRECISION,
    "good_internal" DOUBLE PRECISION,
    "evil_internal" DOUBLE PRECISION,
    "good_external" DOUBLE PRECISION,
    "evil_external" DOUBLE PRECISION,
    "ei_internal" DOUBLE PRECISION,
    "ei_external" DOUBLE PRECISION,
    "ei_combined" DOUBLE PRECISION,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "country_index_hourly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "global_index_hourly" (
    "id" BIGSERIAL NOT NULL,
    "hour_utc" TIMESTAMP(3) NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "global_index_hourly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_index_daily" (
    "id" BIGSERIAL NOT NULL,
    "country_id" INTEGER NOT NULL,
    "date" DATE NOT NULL,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "ei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "von" DOUBLE PRECISION,
    "ni" DOUBLE PRECISION,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "country_index_daily_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "global_index_daily" (
    "id" BIGSERIAL NOT NULL,
    "date" DATE NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "global_index_daily_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_index_weekly" (
    "id" BIGSERIAL NOT NULL,
    "country_id" INTEGER NOT NULL,
    "week_start_date" DATE NOT NULL,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "ei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "von" DOUBLE PRECISION,
    "ni" DOUBLE PRECISION,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "country_index_weekly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "global_index_weekly" (
    "id" BIGSERIAL NOT NULL,
    "week_start_date" DATE NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "global_index_weekly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_index_monthly" (
    "id" BIGSERIAL NOT NULL,
    "country_id" INTEGER NOT NULL,
    "month_start_date" DATE NOT NULL,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "ei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "von" DOUBLE PRECISION,
    "ni" DOUBLE PRECISION,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "country_index_monthly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "global_index_monthly" (
    "id" BIGSERIAL NOT NULL,
    "month_start_date" DATE NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "global_index_monthly_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_index_annually" (
    "id" BIGSERIAL NOT NULL,
    "country_id" INTEGER NOT NULL,
    "year" INTEGER NOT NULL,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "ei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "von" DOUBLE PRECISION,
    "ni" DOUBLE PRECISION,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "country_index_annually_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "global_index_annually" (
    "id" BIGSERIAL NOT NULL,
    "year" INTEGER NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "vote_count" INTEGER NOT NULL DEFAULT 0,
    "verified_vote_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "global_index_annually_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "country_totals_live" (
    "country_id" INTEGER NOT NULL,
    "total_good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "total_evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "last_vote_id" BIGINT,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "country_totals_live_pkey" PRIMARY KEY ("country_id")
);

-- CreateTable
CREATE TABLE "global_index_current" (
    "id" INTEGER NOT NULL,
    "gei" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "g_von" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "good" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "evil" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "global_index_current_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "users_login_key" ON "users"("login");

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "users_phone_key" ON "users"("phone");

-- CreateIndex
CREATE INDEX "users_country_id_idx" ON "users"("country_id");

-- CreateIndex
CREATE INDEX "users_timezone_id_idx" ON "users"("timezone_id");

-- CreateIndex
CREATE INDEX "users_last_achievement_id_idx" ON "users"("last_achievement_id");

-- CreateIndex
CREATE INDEX "auth_tokens_user_id_idx" ON "auth_tokens"("user_id");

-- CreateIndex
CREATE INDEX "votes_user_id_idx" ON "votes"("user_id");

-- CreateIndex
CREATE INDEX "votes_target_country_id_idx" ON "votes"("target_country_id");

-- CreateIndex
CREATE INDEX "votes_createdAt_idx" ON "votes"("createdAt");

-- CreateIndex
CREATE UNIQUE INDEX "user_daily_status_user_id_key" ON "user_daily_status"("user_id");

-- CreateIndex
CREATE UNIQUE INDEX "countries_isoCode_key" ON "countries"("isoCode");

-- CreateIndex
CREATE UNIQUE INDEX "timezones_name_key" ON "timezones"("name");

-- CreateIndex
CREATE UNIQUE INDEX "achievement_categories_slug_key" ON "achievement_categories"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "achievements_code_key" ON "achievements"("code");

-- CreateIndex
CREATE INDEX "achievements_category_id_idx" ON "achievements"("category_id");

-- CreateIndex
CREATE UNIQUE INDEX "user_achievement_stats_user_id_key" ON "user_achievement_stats"("user_id");

-- CreateIndex
CREATE INDEX "user_achievement_stats_user_id_idx" ON "user_achievement_stats"("user_id");

-- CreateIndex
CREATE INDEX "aggregation_watermarks_job_name_period_start_utc_idx" ON "aggregation_watermarks"("job_name", "period_start_utc");

-- CreateIndex
CREATE UNIQUE INDEX "aggregation_watermarks_job_name_period_start_utc_key" ON "aggregation_watermarks"("job_name", "period_start_utc");

-- CreateIndex
CREATE INDEX "country_index_hourly_hour_utc_idx" ON "country_index_hourly"("hour_utc");

-- CreateIndex
CREATE INDEX "country_index_hourly_country_id_hour_utc_idx" ON "country_index_hourly"("country_id", "hour_utc");

-- CreateIndex
CREATE UNIQUE INDEX "country_index_hourly_country_id_hour_utc_key" ON "country_index_hourly"("country_id", "hour_utc");

-- CreateIndex
CREATE UNIQUE INDEX "global_index_hourly_hour_utc_key" ON "global_index_hourly"("hour_utc");

-- CreateIndex
CREATE INDEX "global_index_hourly_hour_utc_idx" ON "global_index_hourly"("hour_utc");

-- CreateIndex
CREATE INDEX "country_index_daily_date_idx" ON "country_index_daily"("date");

-- CreateIndex
CREATE INDEX "country_index_daily_country_id_date_idx" ON "country_index_daily"("country_id", "date");

-- CreateIndex
CREATE UNIQUE INDEX "country_index_daily_country_id_date_key" ON "country_index_daily"("country_id", "date");

-- CreateIndex
CREATE UNIQUE INDEX "global_index_daily_date_key" ON "global_index_daily"("date");

-- CreateIndex
CREATE INDEX "global_index_daily_date_idx" ON "global_index_daily"("date");

-- CreateIndex
CREATE INDEX "country_index_weekly_week_start_date_idx" ON "country_index_weekly"("week_start_date");

-- CreateIndex
CREATE INDEX "country_index_weekly_country_id_week_start_date_idx" ON "country_index_weekly"("country_id", "week_start_date");

-- CreateIndex
CREATE UNIQUE INDEX "country_index_weekly_country_id_week_start_date_key" ON "country_index_weekly"("country_id", "week_start_date");

-- CreateIndex
CREATE UNIQUE INDEX "global_index_weekly_week_start_date_key" ON "global_index_weekly"("week_start_date");

-- CreateIndex
CREATE INDEX "global_index_weekly_week_start_date_idx" ON "global_index_weekly"("week_start_date");

-- CreateIndex
CREATE INDEX "country_index_monthly_month_start_date_idx" ON "country_index_monthly"("month_start_date");

-- CreateIndex
CREATE INDEX "country_index_monthly_country_id_month_start_date_idx" ON "country_index_monthly"("country_id", "month_start_date");

-- CreateIndex
CREATE UNIQUE INDEX "country_index_monthly_country_id_month_start_date_key" ON "country_index_monthly"("country_id", "month_start_date");

-- CreateIndex
CREATE UNIQUE INDEX "global_index_monthly_month_start_date_key" ON "global_index_monthly"("month_start_date");

-- CreateIndex
CREATE INDEX "global_index_monthly_month_start_date_idx" ON "global_index_monthly"("month_start_date");

-- CreateIndex
CREATE INDEX "country_index_annually_year_idx" ON "country_index_annually"("year");

-- CreateIndex
CREATE INDEX "country_index_annually_country_id_year_idx" ON "country_index_annually"("country_id", "year");

-- CreateIndex
CREATE UNIQUE INDEX "country_index_annually_country_id_year_key" ON "country_index_annually"("country_id", "year");

-- CreateIndex
CREATE UNIQUE INDEX "global_index_annually_year_key" ON "global_index_annually"("year");

-- CreateIndex
CREATE INDEX "global_index_annually_year_idx" ON "global_index_annually"("year");

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_timezone_id_fkey" FOREIGN KEY ("timezone_id") REFERENCES "timezones"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_last_achievement_id_fkey" FOREIGN KEY ("last_achievement_id") REFERENCES "achievements"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "auth_tokens" ADD CONSTRAINT "auth_tokens_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "votes" ADD CONSTRAINT "votes_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "votes" ADD CONSTRAINT "votes_target_country_id_fkey" FOREIGN KEY ("target_country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_daily_status" ADD CONSTRAINT "user_daily_status_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "achievements" ADD CONSTRAINT "achievements_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "achievement_categories"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_achievement_stats" ADD CONSTRAINT "user_achievement_stats_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_index_hourly" ADD CONSTRAINT "country_index_hourly_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_index_daily" ADD CONSTRAINT "country_index_daily_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_index_weekly" ADD CONSTRAINT "country_index_weekly_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_index_monthly" ADD CONSTRAINT "country_index_monthly_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_index_annually" ADD CONSTRAINT "country_index_annually_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "country_totals_live" ADD CONSTRAINT "country_totals_live_country_id_fkey" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
