-- ----------------------------
-- Table structure for alarm
-- ----------------------------
UPDATE "alarm" SET "alarm_type" = 'CommunicationAlarm' WHERE "alarm_type" = '1';
UPDATE "alarm" SET "alarm_type" = 'EquipmentAlarm' WHERE "alarm_type" = '2';
UPDATE "alarm" SET "alarm_type" = 'ProcessingFailure' WHERE "alarm_type" = '3';
UPDATE "alarm" SET "alarm_type" = 'EnvironmentalAlarm' WHERE "alarm_type" = '4';
UPDATE "alarm" SET "alarm_type" = 'QualityOfServiceAlarm' WHERE "alarm_type" = '5';
UPDATE "alarm" SET "orig_severity" = 'Critical', "perceived_severity" = 'Critical' WHERE "orig_severity" = '1';
UPDATE "alarm" SET "orig_severity" = 'Major', "perceived_severity" = 'Major' WHERE "orig_severity" = '2';
UPDATE "alarm" SET "orig_severity" = 'Minor', "perceived_severity" = 'Minor' WHERE "orig_severity" = '3';
UPDATE "alarm" SET "orig_severity" = 'Warning', "perceived_severity" = 'Warning' WHERE "orig_severity" = '4';
UPDATE "alarm" SET "orig_severity" = 'Event', "perceived_severity" = 'Event' WHERE "orig_severity" = '5';
UPDATE "alarm" SET "alarm_status" = 'Clear' WHERE "alarm_status" = '0';
UPDATE "alarm" SET "alarm_status" = 'Active' WHERE "alarm_status" = '1';
UPDATE "alarm" SET "ack_state" = 'NotAck' WHERE "ack_state" = '0';
UPDATE "alarm" SET "ack_state" = 'Ack' WHERE "ack_state" = '1';
UPDATE "alarm" SET "clear_type" = 'NotClear' WHERE "clear_type" = '0';
UPDATE "alarm" SET "clear_type" = 'AutoClear' WHERE "clear_type" = '1';
UPDATE "alarm" SET "clear_type" = 'ManualClear' WHERE "clear_type" = '2';
ALTER TABLE "alarm" RENAME TO "alarm_old";
CREATE TABLE "alarm" (
  "id" integer NOT NULL,
  "ne_type" text(32) NOT NULL,
  "ne_id" text(64) NOT NULL,
  "ne_name" text(32),
  "province" text(32),
  "pv_flag" text(10),
  "alarm_seq" integer(11),
  "alarm_id" text(32) NOT NULL,
  "alarm_title" text(255),
  "alarm_code" integer(11),
  "event_time" integer(20),
  "alarm_type" text(64),
  "orig_severity" text(64),
  "perceived_severity" text(64),
  "object_uid" text(64),
  "object_name" text(64),
  "object_type" text(20),
  "location_info" text(2048),
  "alarm_status" text(64),
  "specific_problem" text(255),
  "specific_problem_id" text(100),
  "add_info" text(2048),
  "ack_state" text(64),
  "ack_time" integer(20),
  "ack_user" text(64),
  "clear_type" text(64),
  "clear_time" integer(20),
  "clear_user" text(64),
  "timestamp" integer(20),
  PRIMARY KEY ("id")
);

-- ----------------------------
-- Indexes structure for table alarm
-- ----------------------------
CREATE INDEX IF NOT EXISTS "idx_status_severity_time"
ON "alarm" (
  "alarm_status" ASC,
  "orig_severity" ASC,
  "event_time" ASC
);
CREATE UNIQUE INDEX IF NOT EXISTS "uk_uni_ne_aid"
ON "alarm" (
  "ne_type" ASC,
  "ne_id" ASC,
  "alarm_id" ASC
);

-- ----------------------------
-- Records of alarm
-- ----------------------------
INSERT INTO "alarm" ("id", "ne_type", "ne_id", "ne_name", "province", "pv_flag", "alarm_seq", "alarm_id", "alarm_title", "alarm_code", "event_time", "alarm_type", "orig_severity", "perceived_severity", "object_uid", "object_name", "object_type", "location_info", "alarm_status", "specific_problem", "specific_problem_id", "add_info", "ack_state", "ack_time", "ack_user", "clear_type", "clear_time", "clear_user", "timestamp") SELECT "id", "ne_type", "ne_id", "ne_name", "province", "pv_flag", "alarm_seq", "alarm_id", "alarm_title", "alarm_code", "event_time", "alarm_type", "orig_severity", "perceived_severity", "object_uid", "object_name", "object_type", "location_info", "alarm_status", "specific_problem", "specific_problem_id", "add_info", "ack_state", "ack_time", "ack_user", "clear_type", "clear_time", "clear_user", "timestamp" FROM "alarm_old";
DROP TABLE IF EXISTS "alarm_old";
