# migration_log

migration_id: create migration_log table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `migration_log` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `migration_id` TEXT NOT NULL
  , `sql` TEXT NOT NULL
  , `success` INTEGER NOT NULL
  , `error` TEXT NOT NULL
  , `timestamp` DATETIME NOT NULL
  );


migration_id: create user table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `user` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `login` TEXT NOT NULL
  , `email` TEXT NOT NULL
  , `name` TEXT NULL
  , `password` TEXT NULL
  , `salt` TEXT NULL
  , `rands` TEXT NULL
  , `company` TEXT NULL
  , `account_id` INTEGER NOT NULL
  , `is_admin` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create user table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `user` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `login` TEXT NOT NULL
  , `email` TEXT NOT NULL
  , `name` TEXT NULL
  , `password` TEXT NULL
  , `salt` TEXT NULL
  , `rands` TEXT NULL
  , `company` TEXT NULL
  , `org_id` INTEGER NOT NULL
  , `is_admin` INTEGER NOT NULL
  , `email_verified` INTEGER NULL
  , `theme` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: copy data_source v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `user` (`org_id`
  , `is_admin`
  , `id`
  , `version`
  , `login`
  , `salt`
  , `rands`
  , `company`
  , `created`
  , `updated`
  , `email`
  , `name`
  , `password`) SELECT `account_id`
  , `is_admin`
  , `id`
  , `version`
  , `login`
  , `salt`
  , `rands`
  , `company`
  , `created`
  , `updated`
  , `email`
  , `name`
  , `password` FROM `user_v1`


migration_id: Update is_service_account column to nullable
timestamp: 2022-10-26 09:19:52
sql:
  ALTER TABLE user ADD COLUMN tmp_service_account BOOLEAN DEFAULT 0;
  UPDATE user SET tmp_service_account = is_service_account;
  ALTER TABLE user DROP COLUMN is_service_account;
  ALTER TABLE user RENAME COLUMN tmp_service_account TO is_service_account;


migration_id: create temp user table v1-7
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `temp_user` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `email` TEXT NOT NULL
  , `name` TEXT NULL
  , `role` TEXT NULL
  , `code` TEXT NOT NULL
  , `status` TEXT NOT NULL
  , `invited_by_user_id` INTEGER NULL
  , `email_sent` INTEGER NOT NULL
  , `email_sent_on` DATETIME NULL
  , `remote_addr` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create temp_user v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `temp_user` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `email` TEXT NOT NULL
  , `name` TEXT NULL
  , `role` TEXT NULL
  , `code` TEXT NOT NULL
  , `status` TEXT NOT NULL
  , `invited_by_user_id` INTEGER NULL
  , `email_sent` INTEGER NOT NULL
  , `email_sent_on` DATETIME NULL
  , `remote_addr` TEXT NULL
  , `created` INTEGER NOT NULL DEFAULT 0
  , `updated` INTEGER NOT NULL DEFAULT 0
  );


migration_id: copy temp_user v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `temp_user` (`code`
  , `invited_by_user_id`
  , `email_sent`
  , `email_sent_on`
  , `id`
  , `version`
  , `role`
  , `status`
  , `remote_addr`
  , `org_id`
  , `email`
  , `name`) SELECT `code`
  , `invited_by_user_id`
  , `email_sent`
  , `email_sent_on`
  , `id`
  , `version`
  , `role`
  , `status`
  , `remote_addr`
  , `org_id`
  , `email`
  , `name` FROM `temp_user_tmp_qwerty`


migration_id: create star table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `star` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `user_id` INTEGER NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  );


migration_id: create org table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `org` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `name` TEXT NOT NULL
  , `address1` TEXT NULL
  , `address2` TEXT NULL
  , `city` TEXT NULL
  , `state` TEXT NULL
  , `zip_code` TEXT NULL
  , `country` TEXT NULL
  , `billing_email` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create org_user table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `org_user` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `role` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create dashboard table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `slug` TEXT NOT NULL
  , `title` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `account_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create dashboard_tag table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_tag` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  , `term` TEXT NOT NULL
  );


migration_id: add unique index dashboard_tag.dasboard_id_term
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_tag_dashboard_id_term` ON `dashboard_tag` (`dashboard_id`,`term`);


migration_id: create dashboard v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `slug` TEXT NOT NULL
  , `title` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: copy dashboard v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `dashboard` (`version`
  , `slug`
  , `title`
  , `data`
  , `org_id`
  , `created`
  , `updated`
  , `id`) SELECT `version`
  , `slug`
  , `title`
  , `data`
  , `account_id`
  , `created`
  , `updated`
  , `id` FROM `dashboard_v1`


migration_id: Add unique index for dashboard_org_id_title_folder_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_org_id_folder_id_title` ON `dashboard` (`org_id`,`folder_id`,`title`);


migration_id: create dashboard_provisioning
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_provisioning` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `dashboard_id` INTEGER NULL
  , `name` TEXT NOT NULL
  , `external_id` TEXT NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create dashboard_provisioning v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_provisioning` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `dashboard_id` INTEGER NULL
  , `name` TEXT NOT NULL
  , `external_id` TEXT NOT NULL
  , `updated` INTEGER NOT NULL DEFAULT 0
  );


migration_id: create index IDX_dashboard_provisioning_dashboard_id - v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_dashboard_provisioning_dashboard_id` ON `dashboard_provisioning` (`dashboard_id`);


migration_id: create index IDX_dashboard_provisioning_dashboard_id_name - v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_dashboard_provisioning_dashboard_id_name` ON `dashboard_provisioning` (`dashboard_id`,`name`);


migration_id: copy dashboard_provisioning v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `dashboard_provisioning` (`external_id`
  , `id`
  , `dashboard_id`
  , `name`) SELECT `external_id`
  , `id`
  , `dashboard_id`
  , `name` FROM `dashboard_provisioning_tmp_qwerty`


migration_id: create data_source table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `data_source` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `account_id` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `type` TEXT NOT NULL
  , `name` TEXT NOT NULL
  , `access` TEXT NOT NULL
  , `url` TEXT NOT NULL
  , `password` TEXT NULL
  , `user` TEXT NULL
  , `database` TEXT NULL
  , `basic_auth` INTEGER NOT NULL
  , `basic_auth_user` TEXT NULL
  , `basic_auth_password` TEXT NULL
  , `is_default` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create data_source table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `data_source` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `type` TEXT NOT NULL
  , `name` TEXT NOT NULL
  , `access` TEXT NOT NULL
  , `url` TEXT NOT NULL
  , `password` TEXT NULL
  , `user` TEXT NULL
  , `database` TEXT NULL
  , `basic_auth` INTEGER NOT NULL
  , `basic_auth_user` TEXT NULL
  , `basic_auth_password` TEXT NULL
  , `is_default` INTEGER NOT NULL
  , `json_data` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create api_key table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `api_key` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `account_id` INTEGER NOT NULL
  , `name` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `role` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create api_key table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `api_key` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `name` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `role` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: copy api_key v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `api_key` (`org_id`
  , `name`
  , `key`
  , `role`
  , `created`
  , `updated`
  , `id`) SELECT `account_id`
  , `name`
  , `key`
  , `role`
  , `created`
  , `updated`
  , `id` FROM `api_key_v1`


migration_id: create dashboard_snapshot table v4
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_snapshot` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `name` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `dashboard` TEXT NOT NULL
  , `expires` DATETIME NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create dashboard_snapshot table v5 #2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_snapshot` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `name` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `delete_key` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `external` INTEGER NOT NULL
  , `external_url` TEXT NOT NULL
  , `dashboard` TEXT NOT NULL
  , `expires` DATETIME NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create quota table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `quota` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NULL
  , `user_id` INTEGER NULL
  , `target` TEXT NOT NULL
  , `limit` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create plugin_setting table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `plugin_setting` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NULL
  , `plugin_id` TEXT NOT NULL
  , `enabled` INTEGER NOT NULL
  , `pinned` INTEGER NOT NULL
  , `json_data` TEXT NULL
  , `secure_json_data` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create index UQE_plugin_setting_org_id_plugin_id - v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_plugin_setting_org_id_plugin_id` ON `plugin_setting` (`org_id`,`plugin_id`);


migration_id: create session table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `session` (
  `key` TEXT PRIMARY KEY NOT NULL
  , `data` BLOB NOT NULL
  , `expiry` INTEGER NOT NULL
  );


migration_id: create playlist table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `playlist` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `name` TEXT NOT NULL
  , `interval` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  );


migration_id: create playlist item table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `playlist_item` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `playlist_id` INTEGER NOT NULL
  , `type` TEXT NOT NULL
  , `value` TEXT NOT NULL
  , `title` TEXT NOT NULL
  , `order` INTEGER NOT NULL
  );


migration_id: create preferences table v3
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `preferences` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `home_dashboard_id` INTEGER NOT NULL
  , `timezone` TEXT NOT NULL
  , `theme` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create alert table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `version` INTEGER NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  , `panel_id` INTEGER NOT NULL
  , `org_id` INTEGER NOT NULL
  , `name` TEXT NOT NULL
  , `message` TEXT NOT NULL
  , `state` TEXT NOT NULL
  , `settings` TEXT NOT NULL
  , `frequency` INTEGER NOT NULL
  , `handler` INTEGER NOT NULL
  , `severity` TEXT NOT NULL
  , `silenced` INTEGER NOT NULL
  , `execution_error` TEXT NOT NULL
  , `eval_data` TEXT NULL
  , `eval_date` DATETIME NULL
  , `new_state_date` DATETIME NOT NULL
  , `state_changes` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: Create alert_rule_tag table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_rule_tag` (
  `alert_id` INTEGER NOT NULL
  , `tag_id` INTEGER NOT NULL
  );


migration_id: Create alert_rule_tag table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_rule_tag` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `alert_id` INTEGER NOT NULL
  , `tag_id` INTEGER NOT NULL
  );


sql: CREATE UNIQUE INDEX `UQE_alert_rule_tag_alert_id_tag_id` ON `alert_rule_tag` (`alert_id`,`tag_id`);
timestamp: 2022-10-26 09:19:52
migration_id:
  create index UQE_alert_rule_tag_alert_id_tag_id - Add unique index alert_rule_tag.alert_id_tag_id V2


migration_id: copy alert_rule_tag v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `alert_rule_tag` (`tag_id`
  , `alert_id`) SELECT `tag_id`
  , `alert_id` FROM `alert_rule_tag_v1`


migration_id: create alert_notification table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_notification` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `name` TEXT NOT NULL
  , `type` TEXT NOT NULL
  , `settings` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create notification_journal table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_notification_journal` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `alert_id` INTEGER NOT NULL
  , `notifier_id` INTEGER NOT NULL
  , `sent_at` INTEGER NOT NULL
  , `success` INTEGER NOT NULL
  );


migration_id: add index notification_journal org_id & alert_id & notifier_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_notification_journal_org_id_alert_id_notifier_id` ON `alert_notification_journal` (`org_id`,`alert_id`,`notifier_id`);


migration_id: create alert_notification_state table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_notification_state` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `alert_id` INTEGER NOT NULL
  , `notifier_id` INTEGER NOT NULL
  , `state` TEXT NOT NULL
  , `version` INTEGER NOT NULL
  , `updated_at` INTEGER NOT NULL
  , `alert_rule_state_updated_version` INTEGER NOT NULL
  );


migration_id: add index alert_notification_state org_id & alert_id & notifier_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_alert_notification_state_org_id_alert_id_notifier_id` ON `alert_notification_state` (`org_id`,`alert_id`,`notifier_id`);


migration_id: create annotation table v5
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `annotation` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `alert_id` INTEGER NULL
  , `user_id` INTEGER NULL
  , `dashboard_id` INTEGER NULL
  , `panel_id` INTEGER NULL
  , `category_id` INTEGER NULL
  , `type` TEXT NOT NULL
  , `title` TEXT NOT NULL
  , `text` TEXT NOT NULL
  , `metric` TEXT NULL
  , `prev_state` TEXT NOT NULL
  , `new_state` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `epoch` INTEGER NOT NULL
  );


migration_id: add index annotation 3 v3
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_annotation_org_id_dashboard_id_panel_id_epoch` ON `annotation` (`org_id`,`dashboard_id`,`panel_id`,`epoch`);


migration_id: Create annotation_tag table v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `annotation_tag` (
  `annotation_id` INTEGER NOT NULL
  , `tag_id` INTEGER NOT NULL
  );


migration_id: Add unique index annotation_tag.annotation_id_tag_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_annotation_tag_annotation_id_tag_id` ON `annotation_tag` (`annotation_id`,`tag_id`);


migration_id: Create annotation_tag table v3
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `annotation_tag` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `annotation_id` INTEGER NOT NULL
  , `tag_id` INTEGER NOT NULL
  );


timestamp: 2022-10-26 09:19:52
migration_id:
  create index UQE_annotation_tag_annotation_id_tag_id - Add unique index annotation_tag.annotation_id_tag_id V3

sql:
  CREATE UNIQUE INDEX `UQE_annotation_tag_annotation_id_tag_id` ON `annotation_tag` (`annotation_id`,`tag_id`);


migration_id: copy annotation_tag v2 to v3
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `annotation_tag` (`annotation_id`
  , `tag_id`) SELECT `annotation_id`
  , `tag_id` FROM `annotation_tag_v2`


migration_id: Add index for epoch_end
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_annotation_org_id_epoch_epoch_end` ON `annotation` (`org_id`,`epoch`,`epoch_end`);


migration_id: Add index for org_id_dashboard_id_epoch_end_epoch on annotation table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_annotation_org_id_dashboard_id_epoch_end_epoch` ON `annotation` (`org_id`,`dashboard_id`,`epoch_end`,`epoch`);


migration_id: Add index for org_id_epoch_end_epoch on annotation table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_annotation_org_id_epoch_end_epoch` ON `annotation` (`org_id`,`epoch_end`,`epoch`);


migration_id: create test_data table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `test_data` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `metric1` TEXT NULL
  , `metric2` TEXT NULL
  , `value_big_int` INTEGER NULL
  , `value_double` REAL NULL
  , `value_float` REAL NULL
  , `value_int` INTEGER NULL
  , `time_epoch` INTEGER NOT NULL
  , `time_date_time` DATETIME NOT NULL
  , `time_time_stamp` DATETIME NOT NULL
  );


migration_id: create dashboard_version table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_version` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  , `parent_version` INTEGER NOT NULL
  , `restored_from` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `created_by` INTEGER NOT NULL
  , `message` TEXT NOT NULL
  , `data` TEXT NOT NULL
  );


migration_id: add unique index dashboard_version.dashboard_id and dashboard_version.version
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_version_dashboard_id_version` ON `dashboard_version` (`dashboard_id`,`version`);


migration_id: save existing dashboard data in dashboard_version table v1
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO dashboard_version
  (
  	dashboard_id,
  	version,
  	parent_version,
  	restored_from,
  	created,
  	created_by,
  	message,
  	data
  )
  SELECT
  	dashboard.id,
  	dashboard.version,
  	dashboard.version,
  	dashboard.version,
  	dashboard.updated,
  	COALESCE(dashboard.updated_by, -1),
  	'',
  	dashboard.data
  FROM dashboard;


migration_id: create team table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `team` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `name` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create team member table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `team_member` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `team_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: add unique index team_member_org_id_team_id_user_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_team_member_org_id_team_id_user_id` ON `team_member` (`org_id`,`team_id`,`user_id`);


migration_id: create dashboard acl table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_acl` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  , `user_id` INTEGER NULL
  , `team_id` INTEGER NULL
  , `permission` INTEGER NOT NULL DEFAULT 4
  , `role` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: add unique index dashboard_acl_dashboard_id_user_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_acl_dashboard_id_user_id` ON `dashboard_acl` (`dashboard_id`,`user_id`);


migration_id: add unique index dashboard_acl_dashboard_id_team_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_acl_dashboard_id_team_id` ON `dashboard_acl` (`dashboard_id`,`team_id`);


migration_id: save default acl rules in dashboard_acl table
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO dashboard_acl
  	(
  		org_id,
  		dashboard_id,
  		permission,
  		role,
  		created,
  		updated
  	)
  	VALUES
  		(-1,-1, 1,'Viewer','2017-06-20','2017-06-20'),
  		(-1,-1, 2,'Editor','2017-06-20','2017-06-20')
  	


migration_id: delete acl rules for deleted dashboards and folders
timestamp: 2022-10-26 09:19:52
sql:
  DELETE FROM dashboard_acl WHERE dashboard_id NOT IN (SELECT id FROM dashboard) AND dashboard_id != -1


migration_id: create tag table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `tag` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `key` TEXT NOT NULL
  , `value` TEXT NOT NULL
  );


migration_id: create login attempt table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `login_attempt` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `username` TEXT NOT NULL
  , `ip_address` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  );


migration_id: create login_attempt v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `login_attempt` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `username` TEXT NOT NULL
  , `ip_address` TEXT NOT NULL
  , `created` INTEGER NOT NULL DEFAULT 0
  );


migration_id: copy login_attempt v1 to v2
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO `login_attempt` (`ip_address`
  , `id`
  , `username`) SELECT `ip_address`
  , `id`
  , `username` FROM `login_attempt_tmp_qwerty`


migration_id: create user auth table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `user_auth` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `user_id` INTEGER NOT NULL
  , `auth_module` TEXT NOT NULL
  , `auth_id` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  );


migration_id: create server_lock table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `server_lock` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `operation_uid` TEXT NOT NULL
  , `version` INTEGER NOT NULL
  , `last_execution` INTEGER NOT NULL
  );


migration_id: create user auth token table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `user_auth_token` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `user_id` INTEGER NOT NULL
  , `auth_token` TEXT NOT NULL
  , `prev_auth_token` TEXT NOT NULL
  , `user_agent` TEXT NOT NULL
  , `client_ip` TEXT NOT NULL
  , `auth_token_seen` INTEGER NOT NULL
  , `seen_at` INTEGER NULL
  , `rotated_at` INTEGER NOT NULL
  , `created_at` INTEGER NOT NULL
  , `updated_at` INTEGER NOT NULL
  );


migration_id: create cache_data table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `cache_data` (
  `cache_key` TEXT PRIMARY KEY NOT NULL
  , `data` BLOB NOT NULL
  , `expires` INTEGER NOT NULL
  , `created_at` INTEGER NOT NULL
  );


migration_id: create short_url table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `short_url` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `uid` TEXT NOT NULL
  , `path` TEXT NOT NULL
  , `created_by` INTEGER NOT NULL
  , `created_at` INTEGER NOT NULL
  , `last_seen_at` INTEGER NULL
  );


migration_id: recreate alert_definition table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_definition` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `title` TEXT NOT NULL
  , `condition` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `updated` DATETIME NOT NULL
  , `interval_seconds` INTEGER NOT NULL DEFAULT 60
  , `version` INTEGER NOT NULL DEFAULT 0
  , `uid` TEXT NOT NULL DEFAULT 0
  );


migration_id: recreate alert_definition_version table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_definition_version` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `alert_definition_id` INTEGER NOT NULL
  , `alert_definition_uid` TEXT NOT NULL DEFAULT 0
  , `parent_version` INTEGER NOT NULL
  , `restored_from` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `title` TEXT NOT NULL
  , `condition` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `interval_seconds` INTEGER NOT NULL
  );


migration_id: add index in alert_definition_version table on alert_definition_id and version columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_alert_definition_version_alert_definition_id_version` ON `alert_definition_version` (`alert_definition_id`,`version`);


migration_id: add index in alert_definition_version table on alert_definition_uid and version columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_alert_definition_version_alert_definition_uid_version` ON `alert_definition_version` (`alert_definition_uid`,`version`);


migration_id: create alert_instance table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_instance` (
  `def_org_id` INTEGER NOT NULL
  , `def_uid` TEXT NOT NULL DEFAULT 0
  , `labels` TEXT NOT NULL
  , `labels_hash` TEXT NOT NULL
  , `current_state` TEXT NOT NULL
  , `current_state_since` INTEGER NOT NULL
  , `last_eval_time` INTEGER NOT NULL
  , PRIMARY KEY ( `def_org_id`,`def_uid`,`labels_hash` ));


migration_id: add index in alert_instance table on def_org_id, def_uid and current_state columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_instance_def_org_id_def_uid_current_state` ON `alert_instance` (`def_org_id`,`def_uid`,`current_state`);


migration_id: add index in alert_instance table on def_org_id, current_state columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_instance_def_org_id_current_state` ON `alert_instance` (`def_org_id`,`current_state`);


migration_id: add index rule_org_id, rule_uid, current_state on alert_instance
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_instance_rule_org_id_rule_uid_current_state` ON `alert_instance` (`rule_org_id`,`rule_uid`,`current_state`);


migration_id: add index rule_org_id, current_state on alert_instance
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_instance_rule_org_id_current_state` ON `alert_instance` (`rule_org_id`,`current_state`);


migration_id: create alert_rule table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_rule` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `title` TEXT NOT NULL
  , `condition` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `updated` DATETIME NOT NULL
  , `interval_seconds` INTEGER NOT NULL DEFAULT 60
  , `version` INTEGER NOT NULL DEFAULT 0
  , `uid` TEXT NOT NULL DEFAULT 0
  , `namespace_uid` TEXT NOT NULL
  , `rule_group` TEXT NOT NULL
  , `no_data_state` TEXT NOT NULL DEFAULT 'NoData'
  , `exec_err_state` TEXT NOT NULL DEFAULT 'Alerting'
  );


migration_id: add index in alert_rule on org_id, namespace_uid, group_uid columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_rule_org_id_namespace_uid_rule_group` ON `alert_rule` (`org_id`,`namespace_uid`,`rule_group`);


migration_id: add index in alert_rule on org_id, namespase_uid and title columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_alert_rule_org_id_namespace_uid_title` ON `alert_rule` (`org_id`,`namespace_uid`,`title`);


migration_id: add index in alert_rule on org_id, dashboard_uid and panel_id columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_rule_org_id_dashboard_uid_panel_id` ON `alert_rule` (`org_id`,`dashboard_uid`,`panel_id`);


migration_id: create alert_rule_version table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_rule_version` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `rule_org_id` INTEGER NOT NULL
  , `rule_uid` TEXT NOT NULL DEFAULT 0
  , `rule_namespace_uid` TEXT NOT NULL
  , `rule_group` TEXT NOT NULL
  , `parent_version` INTEGER NOT NULL
  , `restored_from` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `title` TEXT NOT NULL
  , `condition` TEXT NOT NULL
  , `data` TEXT NOT NULL
  , `interval_seconds` INTEGER NOT NULL
  , `no_data_state` TEXT NOT NULL DEFAULT 'NoData'
  , `exec_err_state` TEXT NOT NULL DEFAULT 'Alerting'
  );


migration_id: add index in alert_rule_version table on rule_org_id, rule_uid and version columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_alert_rule_version_rule_org_id_rule_uid_version` ON `alert_rule_version` (`rule_org_id`,`rule_uid`,`version`);


migration_id: add index in alert_rule_version table on rule_org_id, rule_namespace_uid and rule_group columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_alert_rule_version_rule_org_id_rule_namespace_uid_rule_group` ON `alert_rule_version` (`rule_org_id`,`rule_namespace_uid`,`rule_group`);


migration_id: create_alert_configuration_table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_configuration` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `alertmanager_configuration` TEXT NOT NULL
  , `configuration_version` TEXT NOT NULL
  , `created_at` INTEGER NOT NULL
  );


migration_id: add configuration_hash column to alert_configuration
timestamp: 2022-10-26 09:19:52
sql:
  alter table `alert_configuration` ADD COLUMN `configuration_hash` TEXT NOT NULL DEFAULT 'not-yet-calculated' 


migration_id: create_ngalert_configuration_table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `ngalert_configuration` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `alertmanagers` TEXT NULL
  , `created_at` INTEGER NOT NULL
  , `updated_at` INTEGER NOT NULL
  );


migration_id: create provenance_type table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `provenance_type` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `record_key` TEXT NOT NULL
  , `record_type` TEXT NOT NULL
  , `provenance` TEXT NOT NULL
  );


migration_id: add index to uniquify (record_key, record_type, org_id) columns
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_provenance_type_record_type_record_key_org_id` ON `provenance_type` (`record_type`,`record_key`,`org_id`);


migration_id: create alert_image table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `alert_image` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `token` TEXT NOT NULL
  , `path` TEXT NOT NULL
  , `url` TEXT NOT NULL
  , `created_at` DATETIME NOT NULL
  , `expires_at` DATETIME NOT NULL
  );


migration_id: create library_element table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `library_element` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `folder_id` INTEGER NOT NULL
  , `uid` TEXT NOT NULL
  , `name` TEXT NOT NULL
  , `kind` INTEGER NOT NULL
  , `type` TEXT NOT NULL
  , `description` TEXT NOT NULL
  , `model` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `created_by` INTEGER NOT NULL
  , `updated` DATETIME NOT NULL
  , `updated_by` INTEGER NOT NULL
  , `version` INTEGER NOT NULL
  );


migration_id: add index library_element org_id-folder_id-name-kind
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_library_element_org_id_folder_id_name_kind` ON `library_element` (`org_id`,`folder_id`,`name`,`kind`);


migration_id: create library_element_connection table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `library_element_connection` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `element_id` INTEGER NOT NULL
  , `kind` INTEGER NOT NULL
  , `connection_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `created_by` INTEGER NOT NULL
  );


migration_id: add index library_element_connection element_id-kind-connection_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_library_element_connection_element_id_kind_connection_id` ON `library_element_connection` (`element_id`,`kind`,`connection_id`);


migration_id: create dashboard_thumbnail table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_thumbnail` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `dashboard_id` INTEGER NOT NULL
  , `dashboard_version` INTEGER NOT NULL
  , `state` TEXT NOT NULL
  , `panel_id` INTEGER NOT NULL DEFAULT 0
  , `image` BLOB NOT NULL
  , `mime_type` TEXT NOT NULL
  , `kind` TEXT NOT NULL
  , `theme` TEXT NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: add unique indexes for dashboard_thumbnail
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_thumbnail_dashboard_id_panel_id_kind_theme` ON `dashboard_thumbnail` (`dashboard_id`,`panel_id`,`kind`,`theme`);


migration_id: create data_keys table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `data_keys` (
  `name` TEXT PRIMARY KEY NOT NULL
  , `active` INTEGER NOT NULL
  , `scope` TEXT NOT NULL
  , `provider` TEXT NOT NULL
  , `encrypted_data` BLOB NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create secrets table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `secrets` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `namespace` TEXT NOT NULL
  , `type` TEXT NOT NULL
  , `value` TEXT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create kv_store table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `kv_store` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `namespace` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `value` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create permission table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `permission` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `role_id` INTEGER NOT NULL
  , `action` TEXT NOT NULL
  , `scope` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: add unique index role_id_action_scope
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_permission_role_id_action_scope` ON `permission` (`role_id`,`action`,`scope`);


migration_id: create role table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `role` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `name` TEXT NOT NULL
  , `description` TEXT NULL
  , `version` INTEGER NOT NULL
  , `org_id` INTEGER NOT NULL
  , `uid` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: create team role table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `team_role` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `team_id` INTEGER NOT NULL
  , `role_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  );


migration_id: add unique index team_role_org_id_team_id_role_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_team_role_org_id_team_id_role_id` ON `team_role` (`org_id`,`team_id`,`role_id`);


migration_id: create user role table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `user_role` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `role_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  );


migration_id: add unique index user_role_org_id_user_id_role_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_user_role_org_id_user_id_role_id` ON `user_role` (`org_id`,`user_id`,`role_id`);


migration_id: create builtin role table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `builtin_role` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `role` TEXT NOT NULL
  , `role_id` INTEGER NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: add unique index builtin_role_org_id_role_id_role
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_builtin_role_org_id_role_id_role` ON `builtin_role` (`org_id`,`role_id`,`role`);


migration_id: create seed assignment table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `seed_assignment` (
  `builtin_role` TEXT NOT NULL
  , `role_name` TEXT NOT NULL
  );


migration_id: add unique index builtin_role_role_name
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_seed_assignment_builtin_role_role_name` ON `seed_assignment` (`builtin_role`,`role_name`);


migration_id: create query_history table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `query_history` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `uid` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `datasource_uid` TEXT NOT NULL
  , `created_by` INTEGER NOT NULL
  , `created_at` INTEGER NOT NULL
  , `comment` TEXT NOT NULL
  , `queries` TEXT NOT NULL
  );


migration_id: add index query_history.org_id-created_by-datasource_uid
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_query_history_org_id_created_by_datasource_uid` ON `query_history` (`org_id`,`created_by`,`datasource_uid`);


migration_id: create query_history_star table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `query_history_star` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `query_uid` TEXT NOT NULL
  , `user_id` INTEGER NOT NULL
  );


migration_id: add index query_history.user_id-query_uid
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_query_history_star_user_id_query_uid` ON `query_history_star` (`user_id`,`query_uid`);


migration_id: create correlation table v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `correlation` (
  `uid` TEXT NOT NULL
  , `source_uid` TEXT NOT NULL
  , `target_uid` TEXT NULL
  , `label` TEXT NOT NULL
  , `description` TEXT NOT NULL
  , PRIMARY KEY ( `uid`,`source_uid` ));


migration_id: create comment group table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `comment_group` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `object_type` TEXT NOT NULL
  , `object_id` TEXT NOT NULL
  , `settings` TEXT NOT NULL
  , `created` INTEGER NOT NULL
  , `updated` INTEGER NOT NULL
  );


migration_id: add index comment_group.org_id_object_type_object_id
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_comment_group_org_id_object_type_object_id` ON `comment_group` (`org_id`,`object_type`,`object_id`);


migration_id: create comment table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `comment` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `group_id` INTEGER NOT NULL
  , `user_id` INTEGER NOT NULL
  , `content` TEXT NOT NULL
  , `created` INTEGER NOT NULL
  , `updated` INTEGER NOT NULL
  );


migration_id: create entity_events table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `entity_event` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `entity_id` TEXT NOT NULL
  , `event_type` TEXT NOT NULL
  , `created` INTEGER NOT NULL
  );


migration_id: create dashboard public config v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_public_config` (
  `uid` TEXT PRIMARY KEY NOT NULL
  , `dashboard_uid` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `time_settings` TEXT NOT NULL
  , `refresh_rate` INTEGER NOT NULL DEFAULT 30
  , `template_variables` TEXT NULL
  );


migration_id: create index IDX_dashboard_public_config_org_id_dashboard_uid - v1
timestamp: 2022-10-26 09:19:52
sql:
  CREATE INDEX `IDX_dashboard_public_config_org_id_dashboard_uid` ON `dashboard_public_config` (`org_id`,`dashboard_uid`);


migration_id: Recreate dashboard public config v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `dashboard_public_config` (
  `uid` TEXT PRIMARY KEY NOT NULL
  , `dashboard_uid` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `time_settings` TEXT NULL
  , `template_variables` TEXT NULL
  , `access_token` TEXT NOT NULL
  , `created_by` INTEGER NOT NULL
  , `updated_by` INTEGER NULL
  , `created_at` DATETIME NOT NULL
  , `updated_at` DATETIME NULL
  , `is_enabled` INTEGER NOT NULL DEFAULT 0
  );


migration_id: create index UQE_dashboard_public_config_access_token - v2
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_dashboard_public_config_access_token` ON `dashboard_public_config` (`access_token`);


migration_id: create file table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `file` (
  `path` TEXT NOT NULL
  , `path_hash` TEXT NOT NULL
  , `parent_folder_path_hash` TEXT NOT NULL
  , `contents` BLOB NOT NULL
  , `etag` TEXT NOT NULL
  , `cache_control` TEXT NOT NULL
  , `content_disposition` TEXT NOT NULL
  , `updated` DATETIME NOT NULL
  , `created` DATETIME NOT NULL
  , `size` INTEGER NOT NULL
  , `mime_type` TEXT NOT NULL
  );


migration_id: create file_meta table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `file_meta` (
  `path_hash` TEXT NOT NULL
  , `key` TEXT NOT NULL
  , `value` TEXT NOT NULL
  );


migration_id: update seed_assignment role_name column to nullable
timestamp: 2022-10-26 09:19:52
sql:
  ALTER TABLE seed_assignment ADD COLUMN tmp_role_name VARCHAR(190) DEFAULT NULL;
  UPDATE seed_assignment SET tmp_role_name = role_name;
  ALTER TABLE seed_assignment DROP COLUMN role_name;
  ALTER TABLE seed_assignment RENAME COLUMN tmp_role_name TO role_name;


migration_id: add unique index builtin_role_action_scope
timestamp: 2022-10-26 09:19:52
sql:
  CREATE UNIQUE INDEX `UQE_seed_assignment_builtin_role_action_scope` ON `seed_assignment` (`builtin_role`,`action`,`scope`);


migration_id: create folder table
timestamp: 2022-10-26 09:19:52
sql:
  CREATE TABLE IF NOT EXISTS `folder` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
  , `uid` TEXT NOT NULL
  , `org_id` INTEGER NOT NULL
  , `title` TEXT NOT NULL
  , `description` TEXT NULL
  , `parent_uid` TEXT NOT NULL
  , `created` DATETIME NOT NULL
  , `updated` DATETIME NOT NULL
  );


migration_id: copy existing folders from dashboard table
timestamp: 2022-10-26 09:19:52
sql:
  INSERT INTO folder (id, uid, org_id, title, parent_uid, created, updated) SELECT id, uid, org_id, title, 'General', created, updated FROM dashboard WHERE is_folder = 1;


