Skip to content

Instantly share code, notes, and snippets.

@kornicameister
Created March 31, 2016 04:27
Show Gist options
  • Save kornicameister/6bea635fff7e91d2b55a10ca364dac4b to your computer and use it in GitHub Desktop.
Save kornicameister/6bea635fff7e91d2b55a10ca364dac4b to your computer and use it in GitHub Desktop.
SubAlarm table definition
// mysql
CREATE TABLE `sub_alarm` (
`id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`sub_expression_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`expression` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`sporadic` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `fk_sub_alarm` (`alarm_id`),
KEY `fk_sub_alarm_expr` (`sub_expression_id`),
CONSTRAINT `fk_sub_alarm` FOREIGN KEY (`alarm_id`) REFERENCES `alarm` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_sub_alarm_expr` FOREIGN KEY (`sub_expression_id`) REFERENCES `sub_alarm_definition` (`id`)
);
// postgresql
CREATE TABLE sub_alarm (
id character varying(36) NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
expression text NOT NULL,
alarm_id character varying(36) NOT NULL,
sub_expression_id character varying(36),
sporadic boolean NOT NULL DEFAULT FALSE
);
ALTER TABLE ONLY sub_alarm
ADD CONSTRAINT sub_alarm_pkey PRIMARY KEY (id);
ALTER TABLE ONLY sub_alarm
ADD CONSTRAINT fk_rhwkt0j40qbevhhmqpwsw46xa FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE;
// migration for mysql
alter table mon.sub_alarm add column sporadic tinyint(1) NOT NULL DEFAULT '0';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment