-- Status
CREATE TABLE "public"."status" (
  "id" int2 NOT NULL GENERATED ALWAYS AS IDENTITY,
  "name" text NOT NULL,
  PRIMARY KEY ("id")
);
INSERT INTO "public"."status"("name") VALUES ('Activo');
INSERT INTO "public"."status"("name") VALUES ('Inactivo');
INSERT INTO "public"."status"("name") VALUES ('Suspendido');
-- DEVICES
ALTER TABLE "public"."devices" 
  ADD COLUMN "current_bytes" int8,
  ADD COLUMN "is_full_quota" bool;
ALTER TABLE "public"."devices" 
  ADD COLUMN "is_used" bool DEFAULT true;
ALTER TABLE "public"."devices" 
  ADD COLUMN "disabled_since" timestamptz(6),
  ADD COLUMN "disabled_to" timestamptz(6);
ALTER TABLE "public"."devices" 
  ADD COLUMN "recharges_id" uuid;
ALTER TABLE "public"."devices" 
  ADD COLUMN "status_id" int2 DEFAULT 2;
ALTER TABLE "public"."devices" 
  ADD CONSTRAINT "devices_recharge" FOREIGN KEY ("recharges_id") REFERENCES "public"."recharges" ("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "public"."devices" 
  ADD CONSTRAINT "devices_status" FOREIGN KEY ("status_id") REFERENCES "public"."status" ("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- SUSCRIBERS
ALTER TABLE "public"."subscribers" 
  ADD COLUMN "status_id" int2 DEFAULT 2;
ALTER TABLE "public"."subscribers" 
  ADD COLUMN "created_at" timestamptz(6);
ALTER TABLE "public"."subscribers" 
  ADD CONSTRAINT "subscribers_status" FOREIGN KEY ("status_id") REFERENCES "public"."status" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
-- RECHARGES—
ALTER TABLE "public"."recharges" 
  ADD COLUMN "radius" bool,
  ADD COLUMN "users_id" uuid DEFAULT 'f9f63da2-5305-440b-8bbd-2e52b637bc90';
ALTER TABLE "public"."recharges" 
  ADD CONSTRAINT "recharges_users" FOREIGN KEY ("users_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
-- PLANS
ALTER TABLE "public"."plans" 
  ADD COLUMN "is_minimum" bool,
  ADD COLUMN "is_default" bool,
  ADD COLUMN "bytes" int8;