From a7f8cd58cd4c49935a54284e1a081a8921d28c45 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Sat, 15 Aug 2020 18:34:47 +0200 Subject: [PATCH] Remove old migration files --- compose/db/migrate.go | 117 ---------------- compose/db/mysql/static.go | 6 - .../schema/mysql/20180704080000.base.up.sql | 60 -------- .../20180704080001.crm_fields-data.up.sql | 7 - ...0181109133134.crm_content-ownership.up.sql | 1 - ...1109193047.crm_fields-related_types.up.sql | 1 - ...25122152.add_multiple_relationships.up.sql | 6 - ...d_and_visible_to_module_form_fields.up.sql | 1 - ...130.fix-crm-module-form-primary-key.up.sql | 1 - ...04123650.add-crm-content-json-field.up.sql | 1 - ...5326.add-crm-module-form-json-field.up.sql | 1 - ...0181216214630.crm-content-to-record.up.sql | 9 -- .../20181217100000.add-charts-tbl.up.sql | 12 -- .../mysql/20181224122301.rem-crm_field.up.sql | 1 - .../20190108100000.add-triggers-tbl.up.sql | 15 -- ...110175924.rem-crm-record-json-field.up.sql | 1 - ....cleanup-record-tables-and-multival.up.sql | 25 ---- .../20190121132408.record-updated-by.up.sql | 7 - .../mysql/20190227090642.attachment.up.sql | 24 ---- .../20190427180922.change-tbl-prefix.up.sql | 30 ---- .../mysql/20190427210922.namespace-tbl.up.sql | 14 -- .../20190428080000.namespace-refs.up.sql | 61 --------- .../20190428080000.page-timestamps.up.sql | 6 - .../mysql/20190514090000.module_fields.up.sql | 31 ----- .../mysql/20190526090000.permissions.up.sql | 8 -- .../mysql/20190701090000.automation.up.sql | 74 ---------- ...20190825090000.automation-namespace.up.sql | 10 -- .../mysql/20190912125228.field-default.up.sql | 3 - .../mysql/20190917080000.add-handles.up.sql | 3 - .../mysql/20191008152820.settings.up.sql | 10 -- compose/db/schema/mysql/20191009172213.up.sql | 1 - compose/db/schema/mysql/migrations.sql | 8 -- compose/db/schema/mysql/new.sh | 2 - compose/db/types.go | 8 -- messaging/db/migrate.go | 117 ---------------- messaging/db/mysql/static.go | 6 - .../schema/mysql/20180704080000.base.up.sql | 128 ------------------ .../20181009080000.altering_types.up.sql | 3 - .../mysql/20181013080000.channel_views.up.sql | 20 --- .../mysql/20181013080000.replies.up.sql | 2 - .../20181101080000.pins_and_reactions.up.sql | 14 -- .../mysql/20181107080000.mentions.up.sql | 13 -- .../mysql/20181115080000.unreads.up.sql | 8 -- ...20181124173028.remove_events_tables.up.sql | 2 - .../20181205153145.messages-to-utf8mb4.up.sql | 1 - .../20190122191150.membership-flags.up.sql | 1 - .../mysql/20190206112022.prefix-tables.up.sql | 16 --- .../mysql/20190326181923.webhook-table.up.sql | 23 ---- .../mysql/20190526090000.permissions.up.sql | 8 -- .../mysql/20190623080000.unreads.up.sql | 41 ------ ...808000000.channel_membership_policy.up.sql | 1 - .../mysql/20191008125405.settings.up.sql | 10 -- .../mysql/20200602090000.webhook-drop.up.sql | 1 - messaging/db/schema/mysql/migrations.sql | 8 -- messaging/db/schema/mysql/new.sh | 2 - messaging/db/types.go | 8 -- system/db/migrate.go | 117 ---------------- system/db/mysql/static.go | 6 - .../schema/mysql/20180704080000.base.up.sql | 66 --------- ...1124181811.rename_and_prefix_tables.up.sql | 4 - ...81125100429.add_user_kind_and_owner.up.sql | 5 - ...81125153544.satosa_index_not_unique.up.sql | 1 - .../mysql/20181208140000.credentials.up.sql | 19 --- .../20190103203201.users-password-null.up.sql | 1 - .../schema/mysql/20190116102104.rules.up.sql | 8 -- .../20190221001051.rename-team-to-role.up.sql | 5 - ...190226160000.system_roles_and_rules.up.sql | 4 - .../mysql/20190306205033.applications.up.sql | 33 ----- .../mysql/20190326122000.settings.up.sql | 12 -- .../mysql/20190403113201.users-cleanup.up.sql | 3 - .../mysql/20190405090000.internal-auth.up.sql | 1 - .../mysql/20190506090000.compose-app.up.sql | 4 - .../mysql/20190506090000.permissions.up.sql | 40 ------ ...20190826085348.migrate-gplus-google.up.sql | 5 - .../mysql/20190902080000.automation.up.sql | 48 ------- .../mysql/20190924093443.reminders.up.sql | 25 ---- .../20191023213030.settings-cleanup.up.sql | 3 - .../mysql/20200419125927.attachment.up.sql | 22 --- .../mysql/20200508070000.actionlog.up.sql | 20 --- system/db/schema/mysql/migrations.sql | 8 -- system/db/schema/mysql/new.sh | 2 - system/db/types.go | 8 -- 82 files changed, 1468 deletions(-) delete mode 100644 compose/db/migrate.go delete mode 100644 compose/db/mysql/static.go delete mode 100644 compose/db/schema/mysql/20180704080000.base.up.sql delete mode 100644 compose/db/schema/mysql/20180704080001.crm_fields-data.up.sql delete mode 100644 compose/db/schema/mysql/20181109133134.crm_content-ownership.up.sql delete mode 100644 compose/db/schema/mysql/20181109193047.crm_fields-related_types.up.sql delete mode 100644 compose/db/schema/mysql/20181125122152.add_multiple_relationships.up.sql delete mode 100644 compose/db/schema/mysql/20181125132142.add_required_and_visible_to_module_form_fields.up.sql delete mode 100644 compose/db/schema/mysql/20181202163130.fix-crm-module-form-primary-key.up.sql delete mode 100644 compose/db/schema/mysql/20181204123650.add-crm-content-json-field.up.sql delete mode 100644 compose/db/schema/mysql/20181204155326.add-crm-module-form-json-field.up.sql delete mode 100644 compose/db/schema/mysql/20181216214630.crm-content-to-record.up.sql delete mode 100644 compose/db/schema/mysql/20181217100000.add-charts-tbl.up.sql delete mode 100644 compose/db/schema/mysql/20181224122301.rem-crm_field.up.sql delete mode 100644 compose/db/schema/mysql/20190108100000.add-triggers-tbl.up.sql delete mode 100644 compose/db/schema/mysql/20190110175924.rem-crm-record-json-field.up.sql delete mode 100644 compose/db/schema/mysql/20190114072000.cleanup-record-tables-and-multival.up.sql delete mode 100644 compose/db/schema/mysql/20190121132408.record-updated-by.up.sql delete mode 100644 compose/db/schema/mysql/20190227090642.attachment.up.sql delete mode 100644 compose/db/schema/mysql/20190427180922.change-tbl-prefix.up.sql delete mode 100644 compose/db/schema/mysql/20190427210922.namespace-tbl.up.sql delete mode 100644 compose/db/schema/mysql/20190428080000.namespace-refs.up.sql delete mode 100644 compose/db/schema/mysql/20190428080000.page-timestamps.up.sql delete mode 100644 compose/db/schema/mysql/20190514090000.module_fields.up.sql delete mode 100644 compose/db/schema/mysql/20190526090000.permissions.up.sql delete mode 100644 compose/db/schema/mysql/20190701090000.automation.up.sql delete mode 100644 compose/db/schema/mysql/20190825090000.automation-namespace.up.sql delete mode 100644 compose/db/schema/mysql/20190912125228.field-default.up.sql delete mode 100644 compose/db/schema/mysql/20190917080000.add-handles.up.sql delete mode 100644 compose/db/schema/mysql/20191008152820.settings.up.sql delete mode 100644 compose/db/schema/mysql/20191009172213.up.sql delete mode 100644 compose/db/schema/mysql/migrations.sql delete mode 100755 compose/db/schema/mysql/new.sh delete mode 100644 compose/db/types.go delete mode 100644 messaging/db/migrate.go delete mode 100644 messaging/db/mysql/static.go delete mode 100644 messaging/db/schema/mysql/20180704080000.base.up.sql delete mode 100644 messaging/db/schema/mysql/20181009080000.altering_types.up.sql delete mode 100644 messaging/db/schema/mysql/20181013080000.channel_views.up.sql delete mode 100644 messaging/db/schema/mysql/20181013080000.replies.up.sql delete mode 100644 messaging/db/schema/mysql/20181101080000.pins_and_reactions.up.sql delete mode 100644 messaging/db/schema/mysql/20181107080000.mentions.up.sql delete mode 100644 messaging/db/schema/mysql/20181115080000.unreads.up.sql delete mode 100644 messaging/db/schema/mysql/20181124173028.remove_events_tables.up.sql delete mode 100644 messaging/db/schema/mysql/20181205153145.messages-to-utf8mb4.up.sql delete mode 100644 messaging/db/schema/mysql/20190122191150.membership-flags.up.sql delete mode 100644 messaging/db/schema/mysql/20190206112022.prefix-tables.up.sql delete mode 100644 messaging/db/schema/mysql/20190326181923.webhook-table.up.sql delete mode 100644 messaging/db/schema/mysql/20190526090000.permissions.up.sql delete mode 100644 messaging/db/schema/mysql/20190623080000.unreads.up.sql delete mode 100644 messaging/db/schema/mysql/20190808000000.channel_membership_policy.up.sql delete mode 100644 messaging/db/schema/mysql/20191008125405.settings.up.sql delete mode 100644 messaging/db/schema/mysql/20200602090000.webhook-drop.up.sql delete mode 100644 messaging/db/schema/mysql/migrations.sql delete mode 100755 messaging/db/schema/mysql/new.sh delete mode 100644 messaging/db/types.go delete mode 100644 system/db/migrate.go delete mode 100644 system/db/mysql/static.go delete mode 100644 system/db/schema/mysql/20180704080000.base.up.sql delete mode 100644 system/db/schema/mysql/20181124181811.rename_and_prefix_tables.up.sql delete mode 100644 system/db/schema/mysql/20181125100429.add_user_kind_and_owner.up.sql delete mode 100644 system/db/schema/mysql/20181125153544.satosa_index_not_unique.up.sql delete mode 100644 system/db/schema/mysql/20181208140000.credentials.up.sql delete mode 100644 system/db/schema/mysql/20190103203201.users-password-null.up.sql delete mode 100644 system/db/schema/mysql/20190116102104.rules.up.sql delete mode 100644 system/db/schema/mysql/20190221001051.rename-team-to-role.up.sql delete mode 100644 system/db/schema/mysql/20190226160000.system_roles_and_rules.up.sql delete mode 100644 system/db/schema/mysql/20190306205033.applications.up.sql delete mode 100644 system/db/schema/mysql/20190326122000.settings.up.sql delete mode 100644 system/db/schema/mysql/20190403113201.users-cleanup.up.sql delete mode 100644 system/db/schema/mysql/20190405090000.internal-auth.up.sql delete mode 100644 system/db/schema/mysql/20190506090000.compose-app.up.sql delete mode 100644 system/db/schema/mysql/20190506090000.permissions.up.sql delete mode 100644 system/db/schema/mysql/20190826085348.migrate-gplus-google.up.sql delete mode 100644 system/db/schema/mysql/20190902080000.automation.up.sql delete mode 100644 system/db/schema/mysql/20190924093443.reminders.up.sql delete mode 100644 system/db/schema/mysql/20191023213030.settings-cleanup.up.sql delete mode 100644 system/db/schema/mysql/20200419125927.attachment.up.sql delete mode 100644 system/db/schema/mysql/20200508070000.actionlog.up.sql delete mode 100644 system/db/schema/mysql/migrations.sql delete mode 100755 system/db/schema/mysql/new.sh delete mode 100644 system/db/types.go diff --git a/compose/db/migrate.go b/compose/db/migrate.go deleted file mode 100644 index 2a4299dc2..000000000 --- a/compose/db/migrate.go +++ /dev/null @@ -1,117 +0,0 @@ -package db - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "sort" - "strings" - - "github.com/goware/statik/fs" - "github.com/pkg/errors" - "github.com/titpetric/factory" - "go.uber.org/zap" - - "github.com/cortezaproject/corteza-server/compose/db/mysql" -) - -func statements(contents []byte, err error) ([]string, error) { - if err != nil { - return []string{}, err - } - return regexp.MustCompilePOSIX(";$").Split(string(contents), -1), nil -} - -func Migrate(db *factory.DB, log *zap.Logger) error { - log = log.Named("database.migrations") - - statikFS, err := fs.New(mysql.Asset) - if err != nil { - return errors.Wrap(err, "error creating statik filesystem") - } - - var files []string - - fn := func(filename string, info os.FileInfo, err error) error { - _ = err - matched, err := filepath.Match("/*.up.sql", filename) - if matched { - files = append(files, filename) - } - - return err - } - - if err := fs.Walk(statikFS, "/", fn); err != nil { - return errors.Wrap(err, "error when listing files for migrations") - } - - sort.Strings(files) - - if len(files) == 0 { - return errors.New("no files encoded for migration, need at least one SQL file") - } - - migrate := func(filename string, useLog bool) error { - status := migration{ - Project: "crm", - Filename: filename, - } - if useLog { - if err := db.Get(&status, "select * from migrations where project=? and filename=?", status.Project, status.Filename); err != nil { - return err - } - if status.Status == "ok" { - return nil - } - } - - up := func() error { - stmts, err := statements(fs.ReadFile(statikFS, filename)) - if err != nil { - return errors.Wrap(err, fmt.Sprintf("error reading migration %s", filename)) - } - - log.Debug("Running migration", zap.String("filename", filename)) - for idx, query := range stmts { - if strings.TrimSpace(query) != "" && idx >= status.StatementIndex { - status.StatementIndex = idx - if _, err := db.Exec(query); err != nil { - log.Debug("migration error ", zap.String("filename", filename), zap.Error(err)) - return err - } - } - } - - status.Status = "ok" - return nil - } - - err := db.Transaction(up) - if err != nil { - status.Status = err.Error() - } - if useLog { - if err := db.Replace("migrations", status); err != nil { - return errors.Wrap(err, "migration update failed") - } - } - return err - } - - if err := migrate("/migrations.sql", false); err != nil { - return err - } - - db.Exec("LOCK TABLE migrations WRITE;") - defer db.Exec("UNLOCK TABLES") - - for _, filename := range files { - if err := migrate(filename, true); err != nil { - return err - } - } - - return nil -} diff --git a/compose/db/mysql/static.go b/compose/db/mysql/static.go deleted file mode 100644 index c8d2085d9..000000000 --- a/compose/db/mysql/static.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by statik. DO NOT EDIT. - -// Package contains static assets. -package mysql - -var Asset = "PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00 \x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `crm_content` (\n `id` bigint(20) unsigned NOT NULL,\n `module_id` bigint(20) unsigned NOT NULL,\n `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_at` datetime DEFAULT NULL,\n `deleted_at` datetime DEFAULT NULL,\n PRIMARY KEY (`id`,`module_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `crm_content_column` (\n `content_id` bigint(20) NOT NULL,\n `column_name` varchar(255) NOT NULL,\n `column_value` text NOT NULL,\n PRIMARY KEY (`content_id`,`column_name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `crm_field` (\n `field_type` varchar(16) NOT NULL COMMENT 'Short field type (string, boolean,...)',\n `field_name` varchar(255) NOT NULL COMMENT 'Description of field contents',\n `field_template` varchar(255) NOT NULL COMMENT 'HTML template file for field',\n PRIMARY KEY (`field_type`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `crm_module` (\n `id` bigint(20) unsigned NOT NULL,\n `name` varchar(64) NOT NULL COMMENT 'The name of the module',\n `json` json NOT NULL COMMENT 'List of field definitions for the module',\n `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_at` datetime DEFAULT NULL,\n `deleted_at` datetime DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `crm_module_form` (\n `module_id` bigint(20) unsigned NOT NULL,\n `place` tinyint(3) unsigned NOT NULL,\n `kind` varchar(64) NOT NULL COMMENT 'The type of the form input field',\n `name` varchar(64) NOT NULL COMMENT 'The name of the field in the form',\n `label` varchar(255) NOT NULL COMMENT 'The label of the form input',\n `help_text` text NOT NULL COMMENT 'Help text',\n `default_value` text NOT NULL COMMENT 'Default value',\n `max_length` int(10) unsigned NOT NULL COMMENT 'Maximum input length',\n `is_private` tinyint(1) NOT NULL COMMENT 'Contains personal/sensitive data?',\n PRIMARY KEY (`module_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `crm_page` (\n `id` bigint(20) unsigned NOT NULL COMMENT 'Page ID',\n `self_id` bigint(20) unsigned NOT NULL COMMENT 'Parent Page ID',\n `module_id` bigint(20) unsigned NOT NULL COMMENT 'Module ID (optional)',\n `title` varchar(255) NOT NULL COMMENT 'Title (required)',\n `description` text NOT NULL COMMENT 'Description',\n `blocks` json NOT NULL COMMENT 'JSON array of blocks for the page',\n `visible` tinyint(4) NOT NULL COMMENT 'Is page visible in navigation?',\n `weight` int(11) NOT NULL COMMENT 'Order for navigation',\n PRIMARY KEY (`id`) USING BTREE,\n KEY `module_id` (`module_id`),\n KEY `self_id` (`self_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nPK\x07\x08\xac\xe8\x19\x1d\x12\n\x00\x00\x12\n\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00%\x00 \x0020180704080001.crm_fields-data.up.sqlUT\x05\x00\x01\x80Cm8INSERT INTO `crm_field` VALUES ('bool','Boolean value (yes / no)','');\nINSERT INTO `crm_field` VALUES ('email','E-mail input','');\nINSERT INTO `crm_field` VALUES ('enum','Single option picker','');\nINSERT INTO `crm_field` VALUES ('hidden','Hidden value','');\nINSERT INTO `crm_field` VALUES ('stamp','Date/time input','');\nINSERT INTO `crm_field` VALUES ('text','Text input','');\nINSERT INTO `crm_field` VALUES ('textarea','Text input (multi-line)','');\nPK\x07\x08f\x18\x1e\x84\xc5\x01\x00\x00\xc5\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00+\x00 \x0020181109133134.crm_content-ownership.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_content` ADD `user_id` BIGINT UNSIGNED NOT NULL AFTER `module_id`, ADD INDEX (`user_id`);\nPK\x07\x08\xeb!\x81\xc2k\x00\x00\x00k\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00.\x00 \x0020181109193047.crm_fields-related_types.up.sqlUT\x05\x00\x01\x80Cm8INSERT INTO `crm_field` (`field_type`, `field_name`, `field_template`) VALUES ('related', 'Related content', ''), ('related_multi', 'Related content (multiple)', '');PK\x07\x08:.\xfb8\xa6\x00\x00\x00\xa6\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000\x00 \x0020181125122152.add_multiple_relationships.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `crm_content_links` (\n `content_id` bigint(20) unsigned NOT NULL,\n `column_name` varchar(255) NOT NULL,\n `rel_content_id` bigint(20) unsigned NOT NULL,\n PRIMARY KEY (`content_id`,`column_name`,`rel_content_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;PK\x07\x08\xee\x12\x15 \x05\x01\x00\x00\x05\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00D\x00 \x0020181125132142.add_required_and_visible_to_module_form_fields.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_module_form` ADD `is_required` TINYINT(1) NOT NULL AFTER `is_private`, ADD `is_visible` TINYINT(1) NOT NULL AFTER `is_required`;PK\x07\x08\xa5q c\x91\x00\x00\x00\x91\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x005\x00 \x0020181202163130.fix-crm-module-form-primary-key.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_module_form` DROP PRIMARY KEY, ADD PRIMARY KEY(`module_id`, `place`);\nPK\x07\x08\xd9\xd4i\xe3W\x00\x00\x00W\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000\x00 \x0020181204123650.add-crm-content-json-field.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_content` ADD `json` json DEFAULT NULL COMMENT 'Content in JSON format.' AFTER `user_id`;\nPK\x07\x08\"\x96\xd6pj\x00\x00\x00j\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x004\x00 \x0020181204155326.add-crm-module-form-json-field.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_module_form` ADD `json` JSON NOT NULL COMMENT 'Options in JSON format.' AFTER `kind`;PK\x07\x08\xb7\x93\xd4\xf6f\x00\x00\x00f\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00+\x00 \x0020181216214630.crm-content-to-record.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_content` RENAME TO `crm_record`;\nALTER TABLE `crm_record` MODIFY COLUMN `json` json DEFAULT NULL COMMENT 'Records in JSON format.';\n\nALTER TABLE `crm_content_column` RENAME TO `crm_record_column`;\nALTER TABLE `crm_record_column` CHANGE COLUMN `content_id` `record_id` bigint(20);\n\nALTER TABLE `crm_content_links` RENAME TO `crm_record_links`;\nALTER TABLE `crm_record_links` CHANGE COLUMN `content_id` `record_id` bigint(20) unsigned;\nALTER TABLE `crm_record_links` CHANGE COLUMN `rel_content_id` `rel_record_id` bigint(20) unsigned;\nPK\x07\x08mA\xa8\x1e&\x02\x00\x00&\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$\x00 \x0020181217100000.add-charts-tbl.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `crm_chart` (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `name` VARCHAR(64) NOT NULL COMMENT 'The name of the chart',\n `config` JSON NOT NULL COMMENT 'Chart & reporting configuration',\n\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_at` DATETIME DEFAULT NULL,\n `deleted_at` DATETIME DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\xcf\xc6g\xf6\xe4\x01\x00\x00\xe4\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020181224122301.rem-crm_field.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE `crm_field`;\nPK\x07\x08\xae \xfd2\x18\x00\x00\x00\x18\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&\x00 \x0020190108100000.add-triggers-tbl.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `crm_trigger` (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `name` VARCHAR(64) NOT NULL COMMENT 'The name of the trigger',\n `enabled` BOOLEAN NOT NULL COMMENT 'Trigger enabled?',\n `actions` TEXT NOT NULL COMMENT 'All actions that trigger it',\n `source` TEXT NOT NULL COMMENT 'Trigger source',\n `rel_module` BIGINT(20) UNSIGNED NULL COMMENT 'Primary module',\n\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_at` DATETIME DEFAULT NULL,\n `deleted_at` DATETIME DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08+\xad\xb7\xed\xb8\x02\x00\x00\xb8\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/\x00 \x0020190110175924.rem-crm-record-json-field.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_record` DROP COLUMN `json`;\nPK\x07\x08\x94#\xb9\x99-\x00\x00\x00-\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x008\x00 \x0020190114072000.cleanup-record-tables-and-multival.up.sqlUT\x05\x00\x01\x80Cm8-- No more links, we'll handle this through ref field on crm_record_value tbl\nDROP TABLE IF EXISTS `crm_record_links`;\n\n-- Not columns, values\nALTER TABLE `crm_record_column` RENAME TO `crm_record_value`;\n\n-- Simplify names\nALTER TABLE `crm_record_value` CHANGE COLUMN `column_name` `name` VARCHAR(64);\nALTER TABLE `crm_record_value` CHANGE COLUMN `column_value` `value` TEXT;\n\n-- Add reference\nALTER TABLE `crm_record_value` ADD COLUMN `ref` BIGINT UNSIGNED DEFAULT 0 NOT NULL;\nALTER TABLE `crm_record_value` ADD COLUMN `deleted_at` datetime DEFAULT NULL;\nALTER TABLE `crm_record_value` ADD COLUMN `place` INT UNSIGNED DEFAULT 0 NOT NULL;\nALTER TABLE `crm_record_value` DROP PRIMARY KEY, ADD PRIMARY KEY(`record_id`, `name`, `place`);\nCREATE INDEX crm_record_value_ref ON crm_record_value (ref);\n\n\n-- We want this as a real field\nALTER TABLE `crm_module_form` ADD COLUMN `is_multi` TINYINT(1) NOT NULL;\n\n-- This will be handled through meta(json) fieldd\nALTER TABLE `crm_module_form` DROP COLUMN `help_text`;\nALTER TABLE `crm_module_form` DROP COLUMN `max_length`;\nALTER TABLE `crm_module_form` DROP COLUMN `default_Value`;\nPK\x07\x08\x04]{\x1fo\x04\x00\x00o\x04\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x00 \x0020190121132408.record-updated-by.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `crm_record` CHANGE COLUMN `user_id` `owned_by` BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE `crm_record` ADD COLUMN `created_by` BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE `crm_record` ADD COLUMN `updated_by` BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE `crm_record` ADD COLUMN `deleted_by` BIGINT UNSIGNED NOT NULL DEFAULT 0;\nUPDATE crm_record SET created_by = owned_by;\nUPDATE crm_record SET updated_by = owned_by WHERE updated_at IS NOT NULL;\nUPDATE crm_record SET deleted_by = owned_by WHERE deleted_at IS NOT NULL;\nPK\x07\x08h\xe2\xeb\n!\x02\x00\x00!\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x0020190227090642.attachment.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE crm_attachment (\n id BIGINT UNSIGNED NOT NULL,\n rel_owner BIGINT UNSIGNED NOT NULL,\n\n kind VARCHAR(32) NOT NULL,\n\n url VARCHAR(512),\n preview_url VARCHAR(512),\n\n size INT UNSIGNED,\n mimetype VARCHAR(255),\n name TEXT,\n\n meta JSON,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n-- page attachments will be referenced via page-block meta data\n-- module/record attachment will be referenced via crm_record_value\nPK\x07\x08\xce\xde?\x08\xb3\x02\x00\x00\xb3\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x00 \x0020190427180922.change-tbl-prefix.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE IF EXISTS crm_field;\nDROP TABLE IF EXISTS crm_fields;\nDROP TABLE IF EXISTS crm_content;\nDROP TABLE IF EXISTS crm_content_links;\nDROP TABLE IF EXISTS crm_content_column;\nDROP TABLE IF EXISTS crm_module_content;\n\nALTER TABLE crm_attachment\n RENAME TO compose_attachment;\n\nALTER TABLE crm_chart\n RENAME TO compose_chart;\n\nALTER TABLE crm_module\n RENAME TO compose_module;\n\nALTER TABLE crm_module_form\n RENAME TO compose_module_form;\n\nALTER TABLE crm_page\n RENAME TO compose_page;\n\nALTER TABLE crm_record\n RENAME TO compose_record;\n\nALTER TABLE crm_record_value\n RENAME TO compose_record_value;\n\nALTER TABLE crm_trigger\n RENAME TO compose_trigger;\nPK\x07\x08\xf2\x1a)|\x97\x02\x00\x00\x97\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190427210922.namespace-tbl.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `compose_namespace` (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `name` VARCHAR(64) NOT NULL COMMENT 'Name',\n `slug` VARCHAR(64) NOT NULL COMMENT 'URL slug',\n `enabled` BOOLEAN NOT NULL COMMENT 'Is namespace enabled?',\n `meta` JSON NOT NULL COMMENT 'Meta data',\n\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_at` DATETIME DEFAULT NULL,\n `deleted_at` DATETIME DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08m\xeb\xed~R\x02\x00\x00R\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$\x00 \x0020190428080000.namespace-refs.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_attachment`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nALTER TABLE `compose_chart`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nALTER TABLE `compose_module`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nALTER TABLE `compose_page`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nALTER TABLE `compose_record`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nALTER TABLE `compose_trigger`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nUPDATE `compose_attachment` SET `rel_namespace` = 88714882739863655;\nUPDATE `compose_chart` SET `rel_namespace` = 88714882739863655;\nUPDATE `compose_module` SET `rel_namespace` = 88714882739863655;\nUPDATE `compose_page` SET `rel_namespace` = 88714882739863655;\nUPDATE `compose_record` SET `rel_namespace` = 88714882739863655;\nUPDATE `compose_trigger` SET `rel_namespace` = 88714882739863655;\n\n\nALTER TABLE `compose_attachment`\n ADD CONSTRAINT `compose_attachment_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\n\nALTER TABLE `compose_chart`\n ADD CONSTRAINT `compose_chart_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\n\nALTER TABLE `compose_module`\n ADD CONSTRAINT `compose_module_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\n\nALTER TABLE `compose_page`\n ADD CONSTRAINT `compose_page_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\n\nALTER TABLE `compose_record`\n ADD CONSTRAINT `compose_record_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\n\nALTER TABLE `compose_trigger`\n ADD CONSTRAINT `compose_trigger_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\nPK\x07\x08+\xecO\xd2\xd7\x08\x00\x00\xd7\x08\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00%\x00 \x0020190428080000.page-timestamps.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_page`\n ADD COLUMN `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n ADD COLUMN `updated_at` DATETIME DEFAULT NULL,\n ADD COLUMN `deleted_at` DATETIME DEFAULT NULL;\n\nALTER TABLE `compose_page` CHANGE COLUMN `module_id` `rel_module` BIGINT UNSIGNED NOT NULL DEFAULT 0;\nPK\x07\x08\x82\x01Rn1\x01\x00\x001\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190514090000.module_fields.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE compose_module_form\n RENAME TO compose_module_field;\n\n-- Remove orphaned and invalid fields\nDELETE FROM `compose_module_field` WHERE `module_id` NOT IN (SELECT `id` FROM `compose_module`) OR `name` = '';\n\n-- Order and consistency.\nALTER TABLE `compose_module_field`\n ADD COLUMN `id` BIGINT UNSIGNED NOT NULL FIRST,\n ADD COLUMN `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n ADD COLUMN `updated_at` DATETIME DEFAULT NULL,\n ADD COLUMN `deleted_at` DATETIME DEFAULT NULL,\n RENAME COLUMN `module_id` TO `rel_module`,\n RENAME COLUMN `json` TO `options`;\n\n-- Generate IDs for the new field, use module, offset by one (just to start with a different ID)\n-- and use place (0 based, +1 for every field, expecting to be unique per module because of the existing pkey)\nUPDATE `compose_module_field` SET id = rel_module + 1 + place;\n\n-- Drop old primary key (module_id, place)\nALTER TABLE `compose_module_field` DROP PRIMARY KEY, ADD PRIMARY KEY(`id`);\n\n-- Foreign key\nALTER TABLE `compose_module_field`\n ADD CONSTRAINT `compose_module`\n FOREIGN KEY (`rel_module`)\n REFERENCES `compose_module` (`id`);\n\n-- And unique indexes for module+place/name combos.\nCREATE UNIQUE INDEX uid_compose_module_field_place ON compose_module_field (`rel_module`, `place`);\nCREATE UNIQUE INDEX uid_compose_module_field_name ON compose_module_field (`rel_module`, `name`);\nPK\x07\x08\xb1(\xbb\xf0\x8d\x05\x00\x00\x8d\x05\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020190526090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS compose_permission_rules (\n rel_role BIGINT UNSIGNED NOT NULL,\n resource VARCHAR(128) NOT NULL,\n operation VARCHAR(128) NOT NULL,\n access TINYINT(1) NOT NULL,\n\n PRIMARY KEY (rel_role, resource, operation)\n) ENGINE=InnoDB;\nPK\x07\x08\"\xd8\xe5H\x12\x01\x00\x00\x12\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x0020190701090000.automation.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE IF EXISTS compose_automation_trigger;\nDROP TABLE IF EXISTS compose_automation_script;\n\nCREATE TABLE IF NOT EXISTS compose_automation_script (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `name` VARCHAR(64) NOT NULL DEFAULT 'unnamed' COMMENT 'The name of the script',\n `source` TEXT NOT NULL COMMENT 'Source code for the script',\n `source_ref` VARCHAR(200) NOT NULL COMMENT 'Where is the script located (if remote)',\n `async` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Do we run this script asynchronously?',\n `rel_runner` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who is running the script? 0 for invoker',\n `run_in_ua` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Run this script inside user-agent environment',\n `timeout` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Any explicit timeout set for this script (milliseconds)?',\n `critical` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is it critical that this script is executed successfully',\n `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is this script enabled?',\n\n `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `updated_at` DATETIME NULL DEFAULT NULL,\n `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `deleted_at` DATETIME NULL DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE IF NOT EXISTS compose_automation_trigger (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `rel_script` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Script that is triggered',\n\n `resource` VARCHAR(128) NOT NULL COMMENT 'Resource triggering the event',\n `event` VARCHAR(128) NOT NULL COMMENT 'Event triggered',\n `event_condition`\n TEXT NOT NULL COMMENT 'Trigger condition',\n `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Trigger enabled?',\n\n `weight` INT NOT NULL DEFAULT 0,\n\n `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `updated_at` DATETIME NULL DEFAULT NULL,\n `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `deleted_at` DATETIME NULL DEFAULT NULL,\n\n CONSTRAINT `fk_script` FOREIGN KEY (`rel_script`) REFERENCES `compose_automation_script` (`id`),\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n\n\n# Migrate old triggers into scripts\nINSERT INTO compose_automation_script (id, name, source, source_ref, run_in_ua, critical, enabled, created_at, updated_at, deleted_at)\nSELECT id, name, source, '', true, false, enabled, created_at, updated_at, deleted_at from compose_trigger;\n\n# Migrate old triggers into new triggers\nINSERT INTO compose_automation_trigger (id, event, resource, event_condition, rel_script, enabled, created_at, updated_at, deleted_at)\nSELECT id+seq, events.event, 'compose:record', rel_module, id, enabled, created_at, updated_at, deleted_at from compose_trigger AS t INNER JOIN\n ( SELECT 0 as seq, '' AS event\n UNION SELECT 1 as seq, 'manual' AS event\n UNION SELECT 2 as seq, 'beforeCreate' AS event\n UNION SELECT 3 as seq, 'afterCreate' AS event\n UNION SELECT 4 as seq, 'beforeUpdate' AS event\n UNION SELECT 5 as seq, 'afterUpdate' AS event\n UNION SELECT 6 as seq, 'beforeDelete' AS event\n UNION SELECT 7 as seq, 'afterDelete' AS event) AS events ON ((event = '' AND t.actions = '')\n OR (event <> '' AND t.actions LIKE concat('%',event,'%') ));\n# Normalize and cleanup\nUPDATE compose_automation_trigger SET event = 'manual' WHERE event = '';\nDELETE FROM compose_automation_trigger WHERE event_condition IN ('', '0') AND event <> 'manual';\n\nDROP TABLE IF EXISTS compose_trigger;\nPK\x07\x08c\xda\x17\xa4\x13\x11\x00\x00\x13\x11\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x00 \x0020190825090000.automation-namespace.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_automation_script`\n ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`,\n ADD INDEX (`rel_namespace`);\n\nUPDATE `compose_automation_script` SET `rel_namespace` = (SELECT MIN(id) FROM compose_namespace);\n\nALTER TABLE `compose_automation_script`\n ADD CONSTRAINT `compose_automation_script_namespace`\n FOREIGN KEY (`rel_namespace`)\n REFERENCES `compose_namespace` (`id`);\nPK\x07\x08;#~I\x98\x01\x00\x00\x98\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190912125228.field-default.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_module_field`\n ADD `default_value` JSON DEFAULT NULL COMMENT 'Default value as a record value set.'\n AFTER `options`;\nPK\x07\x08&~D\xee\x8d\x00\x00\x00\x8d\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020190917080000.add-handles.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_module` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`;\nALTER TABLE `compose_page` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`;\nALTER TABLE `compose_chart` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`;\nPK\x07\x08}h\xa5\xba\xe4\x00\x00\x00\xe4\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00 \x0020191008152820.settings.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS `compose_settings` (\n rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings',\n name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys',\n value JSON COMMENT 'Setting value',\n\n updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated',\n updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value',\n\n PRIMARY KEY (name, rel_owner)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08WF\x8e\xd1V\x02\x00\x00V\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00 \x0020191009172213.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `compose_record_value` MODIFY `value` LONGTEXT;\nPK\x07\x08\xe0\x1e\x94\xc4<\x00\x00\x00<\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00 \x00migrations.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS `migrations` (\n `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...',\n `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql',\n `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file',\n `status` text NOT NULL COMMENT 'ok or full error message',\n PRIMARY KEY (`project`,`filename`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nPK\x07\x089S\x05%x\x01\x00\x00x\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00 \x00new.shUT\x05\x00\x01\x80Cm8#!/bin/bash\ntouch $(date +%Y%m%d%H%M%S).up.sql\nPK\x07\x08\xc1h\xf1\xfb/\x00\x00\x00/\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xac\xe8\x19\x1d\x12\n\x00\x00\x12\n\x00\x00\x1a\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(f\x18\x1e\x84\xc5\x01\x00\x00\xc5\x01\x00\x00%\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81c\n\x00\x0020180704080001.crm_fields-data.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xeb!\x81\xc2k\x00\x00\x00k\x00\x00\x00+\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x84\x0c\x00\x0020181109133134.crm_content-ownership.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(:.\xfb8\xa6\x00\x00\x00\xa6\x00\x00\x00.\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81Q\x0d\x00\x0020181109193047.crm_fields-related_types.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xee\x12\x15 \x05\x01\x00\x00\x05\x01\x00\x000\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\\\x0e\x00\x0020181125122152.add_multiple_relationships.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xa5q c\x91\x00\x00\x00\x91\x00\x00\x00D\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xc8\x0f\x00\x0020181125132142.add_required_and_visible_to_module_form_fields.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xd9\xd4i\xe3W\x00\x00\x00W\x00\x00\x005\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xd4\x10\x00\x0020181202163130.fix-crm-module-form-primary-key.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\"\x96\xd6pj\x00\x00\x00j\x00\x00\x000\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x97\x11\x00\x0020181204123650.add-crm-content-json-field.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xb7\x93\xd4\xf6f\x00\x00\x00f\x00\x00\x004\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81h\x12\x00\x0020181204155326.add-crm-module-form-json-field.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(mA\xa8\x1e&\x02\x00\x00&\x02\x00\x00+\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x819\x13\x00\x0020181216214630.crm-content-to-record.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xcf\xc6g\xf6\xe4\x01\x00\x00\xe4\x01\x00\x00$\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xc1\x15\x00\x0020181217100000.add-charts-tbl.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xae \xfd2\x18\x00\x00\x00\x18\x00\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x18\x00\x0020181224122301.rem-crm_field.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(+\xad\xb7\xed\xb8\x02\x00\x00\xb8\x02\x00\x00&\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81r\x18\x00\x0020190108100000.add-triggers-tbl.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x94#\xb9\x99-\x00\x00\x00-\x00\x00\x00/\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x87\x1b\x00\x0020190110175924.rem-crm-record-json-field.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x04]{\x1fo\x04\x00\x00o\x04\x00\x008\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x1a\x1c\x00\x0020190114072000.cleanup-record-tables-and-multival.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(h\xe2\xeb\n!\x02\x00\x00!\x02\x00\x00'\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xf8 \x00\x0020190121132408.record-updated-by.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xce\xde?\x08\xb3\x02\x00\x00\xb3\x02\x00\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81w#\x00\x0020190227090642.attachment.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xf2\x1a)|\x97\x02\x00\x00\x97\x02\x00\x00'\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x81&\x00\x0020190427180922.change-tbl-prefix.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(m\xeb\xed~R\x02\x00\x00R\x02\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81v)\x00\x0020190427210922.namespace-tbl.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(+\xecO\xd2\xd7\x08\x00\x00\xd7\x08\x00\x00$\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\",\x00\x0020190428080000.namespace-refs.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x82\x01Rn1\x01\x00\x001\x01\x00\x00%\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81T5\x00\x0020190428080000.page-timestamps.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xb1(\xbb\xf0\x8d\x05\x00\x00\x8d\x05\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xe16\x00\x0020190514090000.module_fields.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\"\xd8\xe5H\x12\x01\x00\x00\x12\x01\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xc8<\x00\x0020190526090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(c\xda\x17\xa4\x13\x11\x00\x00\x13\x11\x00\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x812>\x00\x0020190701090000.automation.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(;#~I\x98\x01\x00\x00\x98\x01\x00\x00*\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x9cO\x00\x0020190825090000.automation-namespace.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(&~D\xee\x8d\x00\x00\x00\x8d\x00\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x95Q\x00\x0020190912125228.field-default.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(}h\xa5\xba\xe4\x00\x00\x00\xe4\x00\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81|R\x00\x0020190917080000.add-handles.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(WF\x8e\xd1V\x02\x00\x00V\x02\x00\x00\x1e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xb8S\x00\x0020191008152820.settings.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xe0\x1e\x94\xc4<\x00\x00\x00<\x00\x00\x00\x15\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81cV\x00\x0020191009172213.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(9S\x05%x\x01\x00\x00x\x01\x00\x00\x0e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xebV\x00\x00migrations.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xc1h\xf1\xfb/\x00\x00\x00/\x00\x00\x00\x06\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\x81\xa8X\x00\x00new.shUT\x05\x00\x01\x80Cm8PK\x05\x06\x00\x00\x00\x00\x1f\x00\x1f\x00@\x0b\x00\x00\x14Y\x00\x00\x00\x00" diff --git a/compose/db/schema/mysql/20180704080000.base.up.sql b/compose/db/schema/mysql/20180704080000.base.up.sql deleted file mode 100644 index c6476ed3e..000000000 --- a/compose/db/schema/mysql/20180704080000.base.up.sql +++ /dev/null @@ -1,60 +0,0 @@ -CREATE TABLE `crm_content` ( - `id` bigint(20) unsigned NOT NULL, - `module_id` bigint(20) unsigned NOT NULL, - `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` datetime DEFAULT NULL, - `deleted_at` datetime DEFAULT NULL, - PRIMARY KEY (`id`,`module_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `crm_content_column` ( - `content_id` bigint(20) NOT NULL, - `column_name` varchar(255) NOT NULL, - `column_value` text NOT NULL, - PRIMARY KEY (`content_id`,`column_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `crm_field` ( - `field_type` varchar(16) NOT NULL COMMENT 'Short field type (string, boolean,...)', - `field_name` varchar(255) NOT NULL COMMENT 'Description of field contents', - `field_template` varchar(255) NOT NULL COMMENT 'HTML template file for field', - PRIMARY KEY (`field_type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `crm_module` ( - `id` bigint(20) unsigned NOT NULL, - `name` varchar(64) NOT NULL COMMENT 'The name of the module', - `json` json NOT NULL COMMENT 'List of field definitions for the module', - `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` datetime DEFAULT NULL, - `deleted_at` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `crm_module_form` ( - `module_id` bigint(20) unsigned NOT NULL, - `place` tinyint(3) unsigned NOT NULL, - `kind` varchar(64) NOT NULL COMMENT 'The type of the form input field', - `name` varchar(64) NOT NULL COMMENT 'The name of the field in the form', - `label` varchar(255) NOT NULL COMMENT 'The label of the form input', - `help_text` text NOT NULL COMMENT 'Help text', - `default_value` text NOT NULL COMMENT 'Default value', - `max_length` int(10) unsigned NOT NULL COMMENT 'Maximum input length', - `is_private` tinyint(1) NOT NULL COMMENT 'Contains personal/sensitive data?', - PRIMARY KEY (`module_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `crm_page` ( - `id` bigint(20) unsigned NOT NULL COMMENT 'Page ID', - `self_id` bigint(20) unsigned NOT NULL COMMENT 'Parent Page ID', - `module_id` bigint(20) unsigned NOT NULL COMMENT 'Module ID (optional)', - `title` varchar(255) NOT NULL COMMENT 'Title (required)', - `description` text NOT NULL COMMENT 'Description', - `blocks` json NOT NULL COMMENT 'JSON array of blocks for the page', - `visible` tinyint(4) NOT NULL COMMENT 'Is page visible in navigation?', - `weight` int(11) NOT NULL COMMENT 'Order for navigation', - PRIMARY KEY (`id`) USING BTREE, - KEY `module_id` (`module_id`), - KEY `self_id` (`self_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - diff --git a/compose/db/schema/mysql/20180704080001.crm_fields-data.up.sql b/compose/db/schema/mysql/20180704080001.crm_fields-data.up.sql deleted file mode 100644 index ebe02db9f..000000000 --- a/compose/db/schema/mysql/20180704080001.crm_fields-data.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO `crm_field` VALUES ('bool','Boolean value (yes / no)',''); -INSERT INTO `crm_field` VALUES ('email','E-mail input',''); -INSERT INTO `crm_field` VALUES ('enum','Single option picker',''); -INSERT INTO `crm_field` VALUES ('hidden','Hidden value',''); -INSERT INTO `crm_field` VALUES ('stamp','Date/time input',''); -INSERT INTO `crm_field` VALUES ('text','Text input',''); -INSERT INTO `crm_field` VALUES ('textarea','Text input (multi-line)',''); diff --git a/compose/db/schema/mysql/20181109133134.crm_content-ownership.up.sql b/compose/db/schema/mysql/20181109133134.crm_content-ownership.up.sql deleted file mode 100644 index f8d8f4a60..000000000 --- a/compose/db/schema/mysql/20181109133134.crm_content-ownership.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_content` ADD `user_id` BIGINT UNSIGNED NOT NULL AFTER `module_id`, ADD INDEX (`user_id`); diff --git a/compose/db/schema/mysql/20181109193047.crm_fields-related_types.up.sql b/compose/db/schema/mysql/20181109193047.crm_fields-related_types.up.sql deleted file mode 100644 index 871140803..000000000 --- a/compose/db/schema/mysql/20181109193047.crm_fields-related_types.up.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO `crm_field` (`field_type`, `field_name`, `field_template`) VALUES ('related', 'Related content', ''), ('related_multi', 'Related content (multiple)', ''); \ No newline at end of file diff --git a/compose/db/schema/mysql/20181125122152.add_multiple_relationships.up.sql b/compose/db/schema/mysql/20181125122152.add_multiple_relationships.up.sql deleted file mode 100644 index 8d1ec6663..000000000 --- a/compose/db/schema/mysql/20181125122152.add_multiple_relationships.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE `crm_content_links` ( - `content_id` bigint(20) unsigned NOT NULL, - `column_name` varchar(255) NOT NULL, - `rel_content_id` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`content_id`,`column_name`,`rel_content_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/compose/db/schema/mysql/20181125132142.add_required_and_visible_to_module_form_fields.up.sql b/compose/db/schema/mysql/20181125132142.add_required_and_visible_to_module_form_fields.up.sql deleted file mode 100644 index 4a5f4d56c..000000000 --- a/compose/db/schema/mysql/20181125132142.add_required_and_visible_to_module_form_fields.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_module_form` ADD `is_required` TINYINT(1) NOT NULL AFTER `is_private`, ADD `is_visible` TINYINT(1) NOT NULL AFTER `is_required`; \ No newline at end of file diff --git a/compose/db/schema/mysql/20181202163130.fix-crm-module-form-primary-key.up.sql b/compose/db/schema/mysql/20181202163130.fix-crm-module-form-primary-key.up.sql deleted file mode 100644 index 3cc580a6b..000000000 --- a/compose/db/schema/mysql/20181202163130.fix-crm-module-form-primary-key.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_module_form` DROP PRIMARY KEY, ADD PRIMARY KEY(`module_id`, `place`); diff --git a/compose/db/schema/mysql/20181204123650.add-crm-content-json-field.up.sql b/compose/db/schema/mysql/20181204123650.add-crm-content-json-field.up.sql deleted file mode 100644 index 401585211..000000000 --- a/compose/db/schema/mysql/20181204123650.add-crm-content-json-field.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_content` ADD `json` json DEFAULT NULL COMMENT 'Content in JSON format.' AFTER `user_id`; diff --git a/compose/db/schema/mysql/20181204155326.add-crm-module-form-json-field.up.sql b/compose/db/schema/mysql/20181204155326.add-crm-module-form-json-field.up.sql deleted file mode 100644 index 07a748860..000000000 --- a/compose/db/schema/mysql/20181204155326.add-crm-module-form-json-field.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_module_form` ADD `json` JSON NOT NULL COMMENT 'Options in JSON format.' AFTER `kind`; \ No newline at end of file diff --git a/compose/db/schema/mysql/20181216214630.crm-content-to-record.up.sql b/compose/db/schema/mysql/20181216214630.crm-content-to-record.up.sql deleted file mode 100644 index e64cafabf..000000000 --- a/compose/db/schema/mysql/20181216214630.crm-content-to-record.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE `crm_content` RENAME TO `crm_record`; -ALTER TABLE `crm_record` MODIFY COLUMN `json` json DEFAULT NULL COMMENT 'Records in JSON format.'; - -ALTER TABLE `crm_content_column` RENAME TO `crm_record_column`; -ALTER TABLE `crm_record_column` CHANGE COLUMN `content_id` `record_id` bigint(20); - -ALTER TABLE `crm_content_links` RENAME TO `crm_record_links`; -ALTER TABLE `crm_record_links` CHANGE COLUMN `content_id` `record_id` bigint(20) unsigned; -ALTER TABLE `crm_record_links` CHANGE COLUMN `rel_content_id` `rel_record_id` bigint(20) unsigned; diff --git a/compose/db/schema/mysql/20181217100000.add-charts-tbl.up.sql b/compose/db/schema/mysql/20181217100000.add-charts-tbl.up.sql deleted file mode 100644 index 082611b46..000000000 --- a/compose/db/schema/mysql/20181217100000.add-charts-tbl.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `crm_chart` ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `name` VARCHAR(64) NOT NULL COMMENT 'The name of the chart', - `config` JSON NOT NULL COMMENT 'Chart & reporting configuration', - - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` DATETIME DEFAULT NULL, - `deleted_at` DATETIME DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/compose/db/schema/mysql/20181224122301.rem-crm_field.up.sql b/compose/db/schema/mysql/20181224122301.rem-crm_field.up.sql deleted file mode 100644 index 891600665..000000000 --- a/compose/db/schema/mysql/20181224122301.rem-crm_field.up.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `crm_field`; diff --git a/compose/db/schema/mysql/20190108100000.add-triggers-tbl.up.sql b/compose/db/schema/mysql/20190108100000.add-triggers-tbl.up.sql deleted file mode 100644 index c04ebbdd3..000000000 --- a/compose/db/schema/mysql/20190108100000.add-triggers-tbl.up.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE `crm_trigger` ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `name` VARCHAR(64) NOT NULL COMMENT 'The name of the trigger', - `enabled` BOOLEAN NOT NULL COMMENT 'Trigger enabled?', - `actions` TEXT NOT NULL COMMENT 'All actions that trigger it', - `source` TEXT NOT NULL COMMENT 'Trigger source', - `rel_module` BIGINT(20) UNSIGNED NULL COMMENT 'Primary module', - - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` DATETIME DEFAULT NULL, - `deleted_at` DATETIME DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/compose/db/schema/mysql/20190110175924.rem-crm-record-json-field.up.sql b/compose/db/schema/mysql/20190110175924.rem-crm-record-json-field.up.sql deleted file mode 100644 index 0841bac6e..000000000 --- a/compose/db/schema/mysql/20190110175924.rem-crm-record-json-field.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `crm_record` DROP COLUMN `json`; diff --git a/compose/db/schema/mysql/20190114072000.cleanup-record-tables-and-multival.up.sql b/compose/db/schema/mysql/20190114072000.cleanup-record-tables-and-multival.up.sql deleted file mode 100644 index 065450a8b..000000000 --- a/compose/db/schema/mysql/20190114072000.cleanup-record-tables-and-multival.up.sql +++ /dev/null @@ -1,25 +0,0 @@ --- No more links, we'll handle this through ref field on crm_record_value tbl -DROP TABLE IF EXISTS `crm_record_links`; - --- Not columns, values -ALTER TABLE `crm_record_column` RENAME TO `crm_record_value`; - --- Simplify names -ALTER TABLE `crm_record_value` CHANGE COLUMN `column_name` `name` VARCHAR(64); -ALTER TABLE `crm_record_value` CHANGE COLUMN `column_value` `value` TEXT; - --- Add reference -ALTER TABLE `crm_record_value` ADD COLUMN `ref` BIGINT UNSIGNED DEFAULT 0 NOT NULL; -ALTER TABLE `crm_record_value` ADD COLUMN `deleted_at` datetime DEFAULT NULL; -ALTER TABLE `crm_record_value` ADD COLUMN `place` INT UNSIGNED DEFAULT 0 NOT NULL; -ALTER TABLE `crm_record_value` DROP PRIMARY KEY, ADD PRIMARY KEY(`record_id`, `name`, `place`); -CREATE INDEX crm_record_value_ref ON crm_record_value (ref); - - --- We want this as a real field -ALTER TABLE `crm_module_form` ADD COLUMN `is_multi` TINYINT(1) NOT NULL; - --- This will be handled through meta(json) fieldd -ALTER TABLE `crm_module_form` DROP COLUMN `help_text`; -ALTER TABLE `crm_module_form` DROP COLUMN `max_length`; -ALTER TABLE `crm_module_form` DROP COLUMN `default_Value`; diff --git a/compose/db/schema/mysql/20190121132408.record-updated-by.up.sql b/compose/db/schema/mysql/20190121132408.record-updated-by.up.sql deleted file mode 100644 index 9c1c095e9..000000000 --- a/compose/db/schema/mysql/20190121132408.record-updated-by.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `crm_record` CHANGE COLUMN `user_id` `owned_by` BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE `crm_record` ADD COLUMN `created_by` BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE `crm_record` ADD COLUMN `updated_by` BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE `crm_record` ADD COLUMN `deleted_by` BIGINT UNSIGNED NOT NULL DEFAULT 0; -UPDATE crm_record SET created_by = owned_by; -UPDATE crm_record SET updated_by = owned_by WHERE updated_at IS NOT NULL; -UPDATE crm_record SET deleted_by = owned_by WHERE deleted_at IS NOT NULL; diff --git a/compose/db/schema/mysql/20190227090642.attachment.up.sql b/compose/db/schema/mysql/20190227090642.attachment.up.sql deleted file mode 100644 index e117e2a15..000000000 --- a/compose/db/schema/mysql/20190227090642.attachment.up.sql +++ /dev/null @@ -1,24 +0,0 @@ -CREATE TABLE crm_attachment ( - id BIGINT UNSIGNED NOT NULL, - rel_owner BIGINT UNSIGNED NOT NULL, - - kind VARCHAR(32) NOT NULL, - - url VARCHAR(512), - preview_url VARCHAR(512), - - size INT UNSIGNED, - mimetype VARCHAR(255), - name TEXT, - - meta JSON, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- page attachments will be referenced via page-block meta data --- module/record attachment will be referenced via crm_record_value diff --git a/compose/db/schema/mysql/20190427180922.change-tbl-prefix.up.sql b/compose/db/schema/mysql/20190427180922.change-tbl-prefix.up.sql deleted file mode 100644 index f8cb60e27..000000000 --- a/compose/db/schema/mysql/20190427180922.change-tbl-prefix.up.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP TABLE IF EXISTS crm_field; -DROP TABLE IF EXISTS crm_fields; -DROP TABLE IF EXISTS crm_content; -DROP TABLE IF EXISTS crm_content_links; -DROP TABLE IF EXISTS crm_content_column; -DROP TABLE IF EXISTS crm_module_content; - -ALTER TABLE crm_attachment - RENAME TO compose_attachment; - -ALTER TABLE crm_chart - RENAME TO compose_chart; - -ALTER TABLE crm_module - RENAME TO compose_module; - -ALTER TABLE crm_module_form - RENAME TO compose_module_form; - -ALTER TABLE crm_page - RENAME TO compose_page; - -ALTER TABLE crm_record - RENAME TO compose_record; - -ALTER TABLE crm_record_value - RENAME TO compose_record_value; - -ALTER TABLE crm_trigger - RENAME TO compose_trigger; diff --git a/compose/db/schema/mysql/20190427210922.namespace-tbl.up.sql b/compose/db/schema/mysql/20190427210922.namespace-tbl.up.sql deleted file mode 100644 index 3be6620b5..000000000 --- a/compose/db/schema/mysql/20190427210922.namespace-tbl.up.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `compose_namespace` ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `name` VARCHAR(64) NOT NULL COMMENT 'Name', - `slug` VARCHAR(64) NOT NULL COMMENT 'URL slug', - `enabled` BOOLEAN NOT NULL COMMENT 'Is namespace enabled?', - `meta` JSON NOT NULL COMMENT 'Meta data', - - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` DATETIME DEFAULT NULL, - `deleted_at` DATETIME DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/compose/db/schema/mysql/20190428080000.namespace-refs.up.sql b/compose/db/schema/mysql/20190428080000.namespace-refs.up.sql deleted file mode 100644 index 022dc3acc..000000000 --- a/compose/db/schema/mysql/20190428080000.namespace-refs.up.sql +++ /dev/null @@ -1,61 +0,0 @@ -ALTER TABLE `compose_attachment` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -ALTER TABLE `compose_chart` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -ALTER TABLE `compose_module` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -ALTER TABLE `compose_page` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -ALTER TABLE `compose_record` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -ALTER TABLE `compose_trigger` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -UPDATE `compose_attachment` SET `rel_namespace` = 88714882739863655; -UPDATE `compose_chart` SET `rel_namespace` = 88714882739863655; -UPDATE `compose_module` SET `rel_namespace` = 88714882739863655; -UPDATE `compose_page` SET `rel_namespace` = 88714882739863655; -UPDATE `compose_record` SET `rel_namespace` = 88714882739863655; -UPDATE `compose_trigger` SET `rel_namespace` = 88714882739863655; - - -ALTER TABLE `compose_attachment` - ADD CONSTRAINT `compose_attachment_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); - -ALTER TABLE `compose_chart` - ADD CONSTRAINT `compose_chart_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); - -ALTER TABLE `compose_module` - ADD CONSTRAINT `compose_module_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); - -ALTER TABLE `compose_page` - ADD CONSTRAINT `compose_page_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); - -ALTER TABLE `compose_record` - ADD CONSTRAINT `compose_record_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); - -ALTER TABLE `compose_trigger` - ADD CONSTRAINT `compose_trigger_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); diff --git a/compose/db/schema/mysql/20190428080000.page-timestamps.up.sql b/compose/db/schema/mysql/20190428080000.page-timestamps.up.sql deleted file mode 100644 index e4e43432f..000000000 --- a/compose/db/schema/mysql/20190428080000.page-timestamps.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE `compose_page` - ADD COLUMN `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - ADD COLUMN `updated_at` DATETIME DEFAULT NULL, - ADD COLUMN `deleted_at` DATETIME DEFAULT NULL; - -ALTER TABLE `compose_page` CHANGE COLUMN `module_id` `rel_module` BIGINT UNSIGNED NOT NULL DEFAULT 0; diff --git a/compose/db/schema/mysql/20190514090000.module_fields.up.sql b/compose/db/schema/mysql/20190514090000.module_fields.up.sql deleted file mode 100644 index 538a2dcbc..000000000 --- a/compose/db/schema/mysql/20190514090000.module_fields.up.sql +++ /dev/null @@ -1,31 +0,0 @@ -ALTER TABLE compose_module_form - RENAME TO compose_module_field; - --- Remove orphaned and invalid fields -DELETE FROM `compose_module_field` WHERE `module_id` NOT IN (SELECT `id` FROM `compose_module`) OR `name` = ''; - --- Order and consistency. -ALTER TABLE `compose_module_field` - ADD COLUMN `id` BIGINT UNSIGNED NOT NULL FIRST, - ADD COLUMN `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - ADD COLUMN `updated_at` DATETIME DEFAULT NULL, - ADD COLUMN `deleted_at` DATETIME DEFAULT NULL, - RENAME COLUMN `module_id` TO `rel_module`, - RENAME COLUMN `json` TO `options`; - --- Generate IDs for the new field, use module, offset by one (just to start with a different ID) --- and use place (0 based, +1 for every field, expecting to be unique per module because of the existing pkey) -UPDATE `compose_module_field` SET id = rel_module + 1 + place; - --- Drop old primary key (module_id, place) -ALTER TABLE `compose_module_field` DROP PRIMARY KEY, ADD PRIMARY KEY(`id`); - --- Foreign key -ALTER TABLE `compose_module_field` - ADD CONSTRAINT `compose_module` - FOREIGN KEY (`rel_module`) - REFERENCES `compose_module` (`id`); - --- And unique indexes for module+place/name combos. -CREATE UNIQUE INDEX uid_compose_module_field_place ON compose_module_field (`rel_module`, `place`); -CREATE UNIQUE INDEX uid_compose_module_field_name ON compose_module_field (`rel_module`, `name`); diff --git a/compose/db/schema/mysql/20190526090000.permissions.up.sql b/compose/db/schema/mysql/20190526090000.permissions.up.sql deleted file mode 100644 index 6492553e0..000000000 --- a/compose/db/schema/mysql/20190526090000.permissions.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS compose_permission_rules ( - rel_role BIGINT UNSIGNED NOT NULL, - resource VARCHAR(128) NOT NULL, - operation VARCHAR(128) NOT NULL, - access TINYINT(1) NOT NULL, - - PRIMARY KEY (rel_role, resource, operation) -) ENGINE=InnoDB; diff --git a/compose/db/schema/mysql/20190701090000.automation.up.sql b/compose/db/schema/mysql/20190701090000.automation.up.sql deleted file mode 100644 index 27fd33448..000000000 --- a/compose/db/schema/mysql/20190701090000.automation.up.sql +++ /dev/null @@ -1,74 +0,0 @@ -DROP TABLE IF EXISTS compose_automation_trigger; -DROP TABLE IF EXISTS compose_automation_script; - -CREATE TABLE IF NOT EXISTS compose_automation_script ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `name` VARCHAR(64) NOT NULL DEFAULT 'unnamed' COMMENT 'The name of the script', - `source` TEXT NOT NULL COMMENT 'Source code for the script', - `source_ref` VARCHAR(200) NOT NULL COMMENT 'Where is the script located (if remote)', - `async` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Do we run this script asynchronously?', - `rel_runner` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who is running the script? 0 for invoker', - `run_in_ua` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Run this script inside user-agent environment', - `timeout` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Any explicit timeout set for this script (milliseconds)?', - `critical` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is it critical that this script is executed successfully', - `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is this script enabled?', - - `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `updated_at` DATETIME NULL DEFAULT NULL, - `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `deleted_at` DATETIME NULL DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE IF NOT EXISTS compose_automation_trigger ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `rel_script` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Script that is triggered', - - `resource` VARCHAR(128) NOT NULL COMMENT 'Resource triggering the event', - `event` VARCHAR(128) NOT NULL COMMENT 'Event triggered', - `event_condition` - TEXT NOT NULL COMMENT 'Trigger condition', - `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Trigger enabled?', - - `weight` INT NOT NULL DEFAULT 0, - - `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `updated_at` DATETIME NULL DEFAULT NULL, - `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `deleted_at` DATETIME NULL DEFAULT NULL, - - CONSTRAINT `fk_script` FOREIGN KEY (`rel_script`) REFERENCES `compose_automation_script` (`id`), - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - - -# Migrate old triggers into scripts -INSERT INTO compose_automation_script (id, name, source, source_ref, run_in_ua, critical, enabled, created_at, updated_at, deleted_at) -SELECT id, name, source, '', true, false, enabled, created_at, updated_at, deleted_at from compose_trigger; - -# Migrate old triggers into new triggers -INSERT INTO compose_automation_trigger (id, event, resource, event_condition, rel_script, enabled, created_at, updated_at, deleted_at) -SELECT id+seq, events.event, 'compose:record', rel_module, id, enabled, created_at, updated_at, deleted_at from compose_trigger AS t INNER JOIN - ( SELECT 0 as seq, '' AS event - UNION SELECT 1 as seq, 'manual' AS event - UNION SELECT 2 as seq, 'beforeCreate' AS event - UNION SELECT 3 as seq, 'afterCreate' AS event - UNION SELECT 4 as seq, 'beforeUpdate' AS event - UNION SELECT 5 as seq, 'afterUpdate' AS event - UNION SELECT 6 as seq, 'beforeDelete' AS event - UNION SELECT 7 as seq, 'afterDelete' AS event) AS events ON ((event = '' AND t.actions = '') - OR (event <> '' AND t.actions LIKE concat('%',event,'%') )); -# Normalize and cleanup -UPDATE compose_automation_trigger SET event = 'manual' WHERE event = ''; -DELETE FROM compose_automation_trigger WHERE event_condition IN ('', '0') AND event <> 'manual'; - -DROP TABLE IF EXISTS compose_trigger; diff --git a/compose/db/schema/mysql/20190825090000.automation-namespace.up.sql b/compose/db/schema/mysql/20190825090000.automation-namespace.up.sql deleted file mode 100644 index e979bf9d4..000000000 --- a/compose/db/schema/mysql/20190825090000.automation-namespace.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -ALTER TABLE `compose_automation_script` - ADD `rel_namespace` BIGINT UNSIGNED NOT NULL AFTER `id`, - ADD INDEX (`rel_namespace`); - -UPDATE `compose_automation_script` SET `rel_namespace` = (SELECT MIN(id) FROM compose_namespace); - -ALTER TABLE `compose_automation_script` - ADD CONSTRAINT `compose_automation_script_namespace` - FOREIGN KEY (`rel_namespace`) - REFERENCES `compose_namespace` (`id`); diff --git a/compose/db/schema/mysql/20190912125228.field-default.up.sql b/compose/db/schema/mysql/20190912125228.field-default.up.sql deleted file mode 100644 index dca12b27f..000000000 --- a/compose/db/schema/mysql/20190912125228.field-default.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `compose_module_field` - ADD `default_value` JSON DEFAULT NULL COMMENT 'Default value as a record value set.' - AFTER `options`; diff --git a/compose/db/schema/mysql/20190917080000.add-handles.up.sql b/compose/db/schema/mysql/20190917080000.add-handles.up.sql deleted file mode 100644 index 25ebf50bc..000000000 --- a/compose/db/schema/mysql/20190917080000.add-handles.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `compose_module` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`; -ALTER TABLE `compose_page` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`; -ALTER TABLE `compose_chart` ADD `handle` VARCHAR(200) NOT NULL AFTER `id`; diff --git a/compose/db/schema/mysql/20191008152820.settings.up.sql b/compose/db/schema/mysql/20191008152820.settings.up.sql deleted file mode 100644 index a1c21d84d..000000000 --- a/compose/db/schema/mysql/20191008152820.settings.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE IF NOT EXISTS `compose_settings` ( - rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings', - name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys', - value JSON COMMENT 'Setting value', - - updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated', - updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value', - - PRIMARY KEY (name, rel_owner) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/compose/db/schema/mysql/20191009172213.up.sql b/compose/db/schema/mysql/20191009172213.up.sql deleted file mode 100644 index 54c091ff8..000000000 --- a/compose/db/schema/mysql/20191009172213.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `compose_record_value` MODIFY `value` LONGTEXT; diff --git a/compose/db/schema/mysql/migrations.sql b/compose/db/schema/mysql/migrations.sql deleted file mode 100644 index e2e13c9ad..000000000 --- a/compose/db/schema/mysql/migrations.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS `migrations` ( - `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...', - `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql', - `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file', - `status` text NOT NULL COMMENT 'ok or full error message', - PRIMARY KEY (`project`,`filename`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - diff --git a/compose/db/schema/mysql/new.sh b/compose/db/schema/mysql/new.sh deleted file mode 100755 index e6249cfe9..000000000 --- a/compose/db/schema/mysql/new.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -touch $(date +%Y%m%d%H%M%S).up.sql diff --git a/compose/db/types.go b/compose/db/types.go deleted file mode 100644 index 8cd781a53..000000000 --- a/compose/db/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package db - -type migration struct { - Project string `db:"project"` - Filename string `db:"filename"` - StatementIndex int `db:"statement_index"` - Status string `db:"status"` -} diff --git a/messaging/db/migrate.go b/messaging/db/migrate.go deleted file mode 100644 index d76642584..000000000 --- a/messaging/db/migrate.go +++ /dev/null @@ -1,117 +0,0 @@ -package db - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "sort" - "strings" - - "github.com/goware/statik/fs" - "github.com/pkg/errors" - "github.com/titpetric/factory" - "go.uber.org/zap" - - "github.com/cortezaproject/corteza-server/messaging/db/mysql" -) - -func statements(contents []byte, err error) ([]string, error) { - if err != nil { - return []string{}, err - } - return regexp.MustCompilePOSIX(";$").Split(string(contents), -1), nil -} - -func Migrate(db *factory.DB, log *zap.Logger) error { - log = log.Named("database.migrations") - - statikFS, err := fs.New(mysql.Asset) - if err != nil { - return errors.Wrap(err, "error creating statik filesystem") - } - - var files []string - - fn := func(filename string, info os.FileInfo, err error) error { - _ = err - matched, err := filepath.Match("/*.up.sql", filename) - if matched { - files = append(files, filename) - } - - return err - } - - if err := fs.Walk(statikFS, "/", fn); err != nil { - return errors.Wrap(err, "error when listing files for migrations") - } - - sort.Strings(files) - - if len(files) == 0 { - return errors.New("no files encoded for migration, need at least one SQL file") - } - - migrate := func(filename string, useLog bool) error { - status := migration{ - Project: "sam", - Filename: filename, - } - if useLog { - if err := db.Get(&status, "select * from migrations where project=? and filename=?", status.Project, status.Filename); err != nil { - return err - } - if status.Status == "ok" { - return nil - } - } - - up := func() error { - stmts, err := statements(fs.ReadFile(statikFS, filename)) - if err != nil { - return errors.Wrap(err, fmt.Sprintf("error reading migration %s", filename)) - } - - log.Debug("Running migration", zap.String("filename", filename)) - for idx, query := range stmts { - if strings.TrimSpace(query) != "" && idx >= status.StatementIndex { - status.StatementIndex = idx - if _, err := db.Exec(query); err != nil { - log.Debug("migration error ", zap.String("filename", filename), zap.Error(err)) - return err - } - } - } - - status.Status = "ok" - return nil - } - - err := db.Transaction(up) - if err != nil { - status.Status = err.Error() - } - if useLog { - if err := db.Replace("migrations", status); err != nil { - return errors.Wrap(err, "migration update failed") - } - } - return err - } - - if err := migrate("/migrations.sql", false); err != nil { - return err - } - - db.Exec("LOCK TABLE migrations WRITE;") - defer db.Exec("UNLOCK TABLES") - - for _, filename := range files { - if err := migrate(filename, true); err != nil { - return err - } - } - - return nil -} diff --git a/messaging/db/mysql/static.go b/messaging/db/mysql/static.go deleted file mode 100644 index 6e0a54754..000000000 --- a/messaging/db/mysql/static.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by statik. DO NOT EDIT. - -// Package contains static assets. -package mysql - -var Asset = "PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00 \x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8-- Keeps all known channels\nCREATE TABLE channels (\n id BIGINT UNSIGNED NOT NULL,\n name TEXT NOT NULL, -- display name of the channel\n topic TEXT NOT NULL,\n meta JSON NOT NULL,\n\n type ENUM ('private', 'public', 'group') NOT NULL DEFAULT 'public',\n\n rel_organisation BIGINT UNSIGNED NOT NULL REFERENCES organisation(id),\n rel_creator BIGINT UNSIGNED NOT NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n archived_at DATETIME NULL,\n deleted_at DATETIME NULL, -- channel soft delete\n\n rel_last_message BIGINT UNSIGNED NOT NULL DEFAULT 0,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n-- handles channel membership\nCREATE TABLE channel_members (\n rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n rel_user BIGINT UNSIGNED NOT NULL,\n\n type ENUM ('owner', 'member', 'invitee') NOT NULL DEFAULT 'member',\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n\n PRIMARY KEY (rel_channel, rel_user)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE channel_views (\n rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n rel_user BIGINT UNSIGNED NOT NULL,\n\n -- timestamp of last view, should be enough to find out which messaghr\n viewed_at DATETIME NOT NULL DEFAULT NOW(),\n\n -- new messages count since last view\n new_since INT UNSIGNED NOT NULL DEFAULT 0,\n\n PRIMARY KEY (rel_user, rel_channel)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE channel_pins (\n rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id),\n rel_user BIGINT UNSIGNED NOT NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n\n PRIMARY KEY (rel_channel, rel_message)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE messages (\n id BIGINT UNSIGNED NOT NULL,\n type TEXT,\n message TEXT NOT NULL,\n meta JSON,\n rel_user BIGINT UNSIGNED NOT NULL,\n rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n reply_to BIGINT UNSIGNED NULL REFERENCES messages(id),\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE reactions (\n id BIGINT UNSIGNED NOT NULL,\n rel_user BIGINT UNSIGNED NOT NULL,\n rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id),\n rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n reaction TEXT NOT NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE attachments (\n id BIGINT UNSIGNED NOT NULL,\n rel_user BIGINT UNSIGNED NOT NULL,\n\n url VARCHAR(512),\n preview_url VARCHAR(512),\n\n size INT UNSIGNED,\n mimetype VARCHAR(255),\n name TEXT,\n\n meta JSON,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE message_attachment (\n rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id),\n rel_attachment BIGINT UNSIGNED NOT NULL REFERENCES attachment(id),\n\n PRIMARY KEY (rel_message)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE event_queue (\n id BIGINT UNSIGNED NOT NULL,\n origin BIGINT UNSIGNED NOT NULL,\n subscriber TEXT,\n payload JSON,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE event_queue_synced (\n origin BIGINT UNSIGNED NOT NULL,\n rel_last BIGINT UNSIGNED NOT NULL,\n\n PRIMARY KEY (origin)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\xd5\x9c\xef\x89V\x10\x00\x00V\x10\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$\x00 \x0020181009080000.altering_types.up.sqlUT\x05\x00\x01\x80Cm8update channels set type = 'group' where type = 'direct';\nalter table channels CHANGE type type enum('private', 'public', 'group');\nalter table channel_members CHANGE type type enum('owner', 'member', 'invitee');\nPK\x07\x08E1\xf5\xa4\xd7\x00\x00\x00\xd7\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020181013080000.channel_views.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE channel_views DROP viewed_at;\nALTER TABLE channel_views ADD rel_last_message_id BIGINT UNSIGNED;\nALTER TABLE channel_views CHANGE new_since new_messages_count INT UNSIGNED;\n\n-- Table structure after these changes:\n-- +---------------------+---------------------+------+-----+---------+-------+\n-- | Field | Type | Null | Key | Default | Extra |\n-- +---------------------+---------------------+------+-----+---------+-------+\n-- | rel_channel | bigint(20) unsigned | NO | PRI | NULL | |\n-- | rel_user | bigint(20) unsigned | NO | PRI | NULL | |\n-- | rel_last_message_id | bigint(20) unsigned | YES | | NULL | |\n-- | new_messages_count | int(10) unsigned | NO | | 0 | |\n-- +---------------------+---------------------+------+-----+---------+-------+\n\n-- Prefill with data\nINSERT INTO channel_views (rel_channel, rel_user, rel_last_message_id)\n SELECT cm.rel_channel, cm.rel_user, max(m.ID)\n FROM channel_members AS cm INNER JOIN messages AS m ON (m.rel_channel = cm.rel_channel)\n GROUP BY cm.rel_channel, cm.rel_user;\n\nPK\x07\x08`\xcbP\xf9t\x04\x00\x00t\x04\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00 \x0020181013080000.replies.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE messages CHANGE reply_to reply_to BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE messages ADD replies INT UNSIGNED NOT NULL DEFAULT 0;\nPK\x07\x08m\xedWA\x94\x00\x00\x00\x94\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00(\x00 \x0020181101080000.pins_and_reactions.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE channel_pins;\nDROP TABLE reactions;\n\nCREATE TABLE message_flags (\n id BIGINT UNSIGNED NOT NULL,\n rel_channel BIGINT UNSIGNED NOT NULL,\n rel_message BIGINT UNSIGNED NOT NULL,\n rel_user BIGINT UNSIGNED NOT NULL,\n flag TEXT,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08eA\x1eo\x90\x01\x00\x00\x90\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00 \x0020181107080000.mentions.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE mentions (\n id BIGINT UNSIGNED NOT NULL,\n rel_channel BIGINT UNSIGNED NOT NULL,\n rel_message BIGINT UNSIGNED NOT NULL,\n rel_user BIGINT UNSIGNED NOT NULL,\n rel_mentioned_by BIGINT UNSIGNED NOT NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE INDEX lookup_mentions ON mentions (rel_mentioned_by)\nPK\x07\x08\xfb\xe8\x9b\x98\xac\x01\x00\x00\xac\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00 \x0020181115080000.unreads.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE channel_views RENAME TO unreads;\n\nALTER TABLE unreads ADD rel_reply_to BIGINT UNSIGNED NOT NULL AFTER rel_channel;\nALTER TABLE unreads CHANGE rel_channel rel_channel BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE unreads CHANGE rel_user rel_user BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE unreads CHANGE rel_last_message_id rel_last_message BIGINT UNSIGNED NOT NULL DEFAULT 0;\nALTER TABLE unreads CHANGE new_messages_count count INT UNSIGNED NOT NULL DEFAULT 0;\n\nPK\x07\x08jf1Q+\x02\x00\x00+\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x00 \x0020181124173028.remove_events_tables.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE event_queue;\nDROP TABLE event_queue_synced;PK\x07\x08\xdd.y06\x00\x00\x006\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)\x00 \x0020181205153145.messages-to-utf8mb4.up.sqlUT\x05\x00\x01\x80Cm8alter table messages convert to character set utf8mb4 collate utf8mb4_unicode_ci;PK\x07\x08Ig\xbfOQ\x00\x00\x00Q\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&\x00 \x0020190122191150.membership-flags.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE channel_members ADD flag ENUM ('pinned', 'hidden', 'ignored', '') NOT NULL DEFAULT '' AFTER `type`;\nPK\x07\x084\xfb\xe3\xf4p\x00\x00\x00p\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190206112022.prefix-tables.up.sqlUT\x05\x00\x01\x80Cm8-- misc tables\n\nALTER TABLE attachments RENAME TO messaging_attachment;\nALTER TABLE mentions RENAME TO messaging_mention;\nALTER TABLE unreads RENAME TO messaging_unread;\n\n-- channel tables\n\nALTER TABLE channels RENAME TO messaging_channel;\nALTER TABLE channel_members RENAME TO messaging_channel_member;\n\n-- message tables\n\nALTER TABLE messages RENAME TO messaging_message;\nALTER TABLE message_attachment RENAME TO messaging_message_attachment;\nALTER TABLE message_flags RENAME TO messaging_message_flag;\nPK\x07\x08\x145\xde}Q\x02\x00\x00Q\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190326181923.webhook-table.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `messaging_webhook` (\n `id` bigint(20) unsigned NOT NULL,\n `kind` varchar(8) NOT NULL COMMENT 'Kind: incoming, outgoing',\n `token` varchar(255) NOT NULL COMMENT 'Authentication token',\n `rel_owner` bigint(20) unsigned NOT NULL COMMENT 'Webhook owner User ID',\n `rel_user` bigint(20) unsigned NOT NULL COMMENT 'Webhook message User ID',\n `rel_channel` bigint(20) unsigned NOT NULL COMMENT 'Channel ID',\n `outgoing_trigger` varchar(32) NOT NULL COMMENT 'Outgoing command trigger',\n `outgoing_url` varchar(255) NOT NULL COMMENT 'URL for POST request',\n `created_at` datetime NOT NULL,\n `updated_at` datetime NULL,\n `deleted_at` datetime NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n-- get webhook by command trigger\nALTER TABLE `messaging_webhook` ADD UNIQUE(`outgoing_trigger`);\n\n-- list webhooks by owner (list your own webhooks)\nALTER TABLE `messaging_webhook` ADD INDEX(`rel_owner`);\n\n-- list webhooks on a channel\nALTER TABLE `messaging_webhook` ADD INDEX(`rel_channel`);\nPK\x07\x08\x16\x95.\xf3\xf7\x03\x00\x00\xf7\x03\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020190526090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS messaging_permission_rules (\n rel_role BIGINT UNSIGNED NOT NULL,\n resource VARCHAR(128) NOT NULL,\n operation VARCHAR(128) NOT NULL,\n access TINYINT(1) NOT NULL,\n\n PRIMARY KEY (rel_role, resource, operation)\n) ENGINE=InnoDB;\nPK\x07\x08\xf0d&V\x14\x01\x00\x00\x14\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00 \x0020190623080000.unreads.up.sqlUT\x05\x00\x01\x80Cm8UPDATE `messaging_unread` SET rel_reply_to = 0 WHERE rel_reply_to IS NULL;\nALTER TABLE `messaging_unread` CHANGE COLUMN `rel_reply_to` `rel_reply_to` BIGINT UNSIGNED NOT NULL;\nALTER TABLE `messaging_unread` DROP PRIMARY KEY, ADD PRIMARY KEY(`rel_channel`, `rel_reply_to`, `rel_user`);\n\n-- Add entries for all (unexisting) unreads (channels & threads)\nINSERT IGNORE INTO messaging_unread\n (rel_channel, rel_reply_to, rel_user)\nSELECT DISTINCT cm.rel_channel, msg.id, cm.rel_user\n FROM messaging_channel_member AS cm\n INNER JOIN messaging_message AS msg ON (cm.rel_channel = msg.rel_channel AND replies > 0)\n WHERE NOT EXISTS (SELECT 1 FROM messaging_unread AS u WHERE u.rel_reply_to = msg.id AND u.rel_user = cm.rel_user)\n AND msg.rel_user > 0\n\nUNION\n\nSELECT DISTINCT cm.rel_channel, 0, cm.rel_user\n FROM messaging_channel_member AS cm\n WHERE NOT EXISTS (SELECT 1 FROM messaging_unread AS u WHERE u.rel_channel = cm.rel_channel AND u.rel_user = cm.rel_user)\n AND cm.rel_user > 0\n;\n\n\n-- Update counters for channel messages\nINSERT IGNORE INTO messaging_unread\n (rel_channel, rel_reply_to, rel_user, count, rel_last_message)\nSELECT u.rel_channel, 0, u.rel_user, COUNT(m.id), u.rel_last_message\n FROM messaging_unread AS u\n INNER JOIN messaging_message AS m ON (u.rel_channel = m.rel_channel AND m.id > u.rel_last_message)\n WHERE u.rel_reply_to = 0\n AND m.reply_to = 0\n GROUP BY u.rel_channel, u.rel_user;\n\n-- Update counters for thread messages\n\nINSERT IGNORE INTO messaging_unread\n (rel_channel, rel_reply_to, rel_user, count, rel_last_message)\nSELECT u.rel_channel, rpl.reply_to, u.rel_user, COUNT(rpl.id), u.rel_last_message\n FROM messaging_unread AS u\n INNER JOIN messaging_message AS rpl ON (u.rel_channel = rpl.rel_channel AND rpl.reply_to = u.rel_reply_to AND rpl.id > u.rel_last_message)\n WHERE rpl.replies > 0 AND u.rel_reply_to > 0\n GROUP BY u.rel_channel, rpl.reply_to, u.rel_user;\nPK\x07\x08\xa3(M\xda\xa1\x07\x00\x00\xa1\x07\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/\x00 \x0020190808000000.channel_membership_policy.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `messaging_channel` ADD `membership_policy` ENUM ('featured', 'forced', '') NOT NULL DEFAULT '' AFTER `type`;\nPK\x07\x08E\xa4\xe3\xf0z\x00\x00\x00z\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00 \x0020191008125405.settings.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS `messaging_settings` (\n rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings',\n name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys',\n value JSON COMMENT 'Setting value',\n\n updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated',\n updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value',\n\n PRIMARY KEY (name, rel_owner)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\xab\xbe\x82\xefX\x02\x00\x00X\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\"\x00 \x0020200602090000.webhook-drop.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE `messaging_webhook`;\nPK\x07\x082X\xb7\x8a \x00\x00\x00 \x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00 \x00migrations.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS `migrations` (\n `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...',\n `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql',\n `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file',\n `status` TEXT NOT NULL COMMENT 'ok or full error message',\n PRIMARY KEY (`project`,`filename`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nPK\x07\x08\x0d\xa5T2x\x01\x00\x00x\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00 \x00new.shUT\x05\x00\x01\x80Cm8#!/bin/bash\ntouch $(date +%Y%m%d%H%M%S).up.sqlPK\x07\x08s\xd4N*.\x00\x00\x00.\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xd5\x9c\xef\x89V\x10\x00\x00V\x10\x00\x00\x1a\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(E1\xf5\xa4\xd7\x00\x00\x00\xd7\x00\x00\x00$\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xa7\x10\x00\x0020181009080000.altering_types.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(`\xcbP\xf9t\x04\x00\x00t\x04\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xd9\x11\x00\x0020181013080000.channel_views.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(m\xedWA\x94\x00\x00\x00\x94\x00\x00\x00\x1d\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xa7\x16\x00\x0020181013080000.replies.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(eA\x1eo\x90\x01\x00\x00\x90\x01\x00\x00(\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x8f\x17\x00\x0020181101080000.pins_and_reactions.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xfb\xe8\x9b\x98\xac\x01\x00\x00\xac\x01\x00\x00\x1e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81~\x19\x00\x0020181107080000.mentions.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(jf1Q+\x02\x00\x00+\x02\x00\x00\x1d\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x7f\x1b\x00\x0020181115080000.unreads.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xdd.y06\x00\x00\x006\x00\x00\x00*\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xfe\x1d\x00\x0020181124173028.remove_events_tables.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(Ig\xbfOQ\x00\x00\x00Q\x00\x00\x00)\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x95\x1e\x00\x0020181205153145.messages-to-utf8mb4.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(4\xfb\xe3\xf4p\x00\x00\x00p\x00\x00\x00&\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81F\x1f\x00\x0020190122191150.membership-flags.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x145\xde}Q\x02\x00\x00Q\x02\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x13 \x00\x0020190206112022.prefix-tables.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x16\x95.\xf3\xf7\x03\x00\x00\xf7\x03\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xbe\"\x00\x0020190326181923.webhook-table.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xf0d&V\x14\x01\x00\x00\x14\x01\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x0f'\x00\x0020190526090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xa3(M\xda\xa1\x07\x00\x00\xa1\x07\x00\x00\x1d\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81{(\x00\x0020190623080000.unreads.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(E\xa4\xe3\xf0z\x00\x00\x00z\x00\x00\x00/\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81p0\x00\x0020190808000000.channel_membership_policy.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xab\xbe\x82\xefX\x02\x00\x00X\x02\x00\x00\x1e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81P1\x00\x0020191008125405.settings.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(2X\xb7\x8a \x00\x00\x00 \x00\x00\x00\"\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xfd3\x00\x0020200602090000.webhook-drop.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x0d\xa5T2x\x01\x00\x00x\x01\x00\x00\x0e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81v4\x00\x00migrations.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(s\xd4N*.\x00\x00\x00.\x00\x00\x00\x06\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\x8136\x00\x00new.shUT\x05\x00\x01\x80Cm8PK\x05\x06\x00\x00\x00\x00\x13\x00\x13\x00v\x06\x00\x00\x9e6\x00\x00\x00\x00" diff --git a/messaging/db/schema/mysql/20180704080000.base.up.sql b/messaging/db/schema/mysql/20180704080000.base.up.sql deleted file mode 100644 index b9b1d6706..000000000 --- a/messaging/db/schema/mysql/20180704080000.base.up.sql +++ /dev/null @@ -1,128 +0,0 @@ --- Keeps all known channels -CREATE TABLE channels ( - id BIGINT UNSIGNED NOT NULL, - name TEXT NOT NULL, -- display name of the channel - topic TEXT NOT NULL, - meta JSON NOT NULL, - - type ENUM ('private', 'public', 'group') NOT NULL DEFAULT 'public', - - rel_organisation BIGINT UNSIGNED NOT NULL REFERENCES organisation(id), - rel_creator BIGINT UNSIGNED NOT NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - archived_at DATETIME NULL, - deleted_at DATETIME NULL, -- channel soft delete - - rel_last_message BIGINT UNSIGNED NOT NULL DEFAULT 0, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- handles channel membership -CREATE TABLE channel_members ( - rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id), - rel_user BIGINT UNSIGNED NOT NULL, - - type ENUM ('owner', 'member', 'invitee') NOT NULL DEFAULT 'member', - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - - PRIMARY KEY (rel_channel, rel_user) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE channel_views ( - rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id), - rel_user BIGINT UNSIGNED NOT NULL, - - -- timestamp of last view, should be enough to find out which messaghr - viewed_at DATETIME NOT NULL DEFAULT NOW(), - - -- new messages count since last view - new_since INT UNSIGNED NOT NULL DEFAULT 0, - - PRIMARY KEY (rel_user, rel_channel) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE channel_pins ( - rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id), - rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id), - rel_user BIGINT UNSIGNED NOT NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - - PRIMARY KEY (rel_channel, rel_message) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE messages ( - id BIGINT UNSIGNED NOT NULL, - type TEXT, - message TEXT NOT NULL, - meta JSON, - rel_user BIGINT UNSIGNED NOT NULL, - rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id), - reply_to BIGINT UNSIGNED NULL REFERENCES messages(id), - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE reactions ( - id BIGINT UNSIGNED NOT NULL, - rel_user BIGINT UNSIGNED NOT NULL, - rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id), - rel_channel BIGINT UNSIGNED NOT NULL REFERENCES channels(id), - reaction TEXT NOT NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE attachments ( - id BIGINT UNSIGNED NOT NULL, - rel_user BIGINT UNSIGNED NOT NULL, - - url VARCHAR(512), - preview_url VARCHAR(512), - - size INT UNSIGNED, - mimetype VARCHAR(255), - name TEXT, - - meta JSON, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE message_attachment ( - rel_message BIGINT UNSIGNED NOT NULL REFERENCES messages(id), - rel_attachment BIGINT UNSIGNED NOT NULL REFERENCES attachment(id), - - PRIMARY KEY (rel_message) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE event_queue ( - id BIGINT UNSIGNED NOT NULL, - origin BIGINT UNSIGNED NOT NULL, - subscriber TEXT, - payload JSON, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE event_queue_synced ( - origin BIGINT UNSIGNED NOT NULL, - rel_last BIGINT UNSIGNED NOT NULL, - - PRIMARY KEY (origin) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/messaging/db/schema/mysql/20181009080000.altering_types.up.sql b/messaging/db/schema/mysql/20181009080000.altering_types.up.sql deleted file mode 100644 index eb47edad7..000000000 --- a/messaging/db/schema/mysql/20181009080000.altering_types.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -update channels set type = 'group' where type = 'direct'; -alter table channels CHANGE type type enum('private', 'public', 'group'); -alter table channel_members CHANGE type type enum('owner', 'member', 'invitee'); diff --git a/messaging/db/schema/mysql/20181013080000.channel_views.up.sql b/messaging/db/schema/mysql/20181013080000.channel_views.up.sql deleted file mode 100644 index 7e0773026..000000000 --- a/messaging/db/schema/mysql/20181013080000.channel_views.up.sql +++ /dev/null @@ -1,20 +0,0 @@ -ALTER TABLE channel_views DROP viewed_at; -ALTER TABLE channel_views ADD rel_last_message_id BIGINT UNSIGNED; -ALTER TABLE channel_views CHANGE new_since new_messages_count INT UNSIGNED; - --- Table structure after these changes: --- +---------------------+---------------------+------+-----+---------+-------+ --- | Field | Type | Null | Key | Default | Extra | --- +---------------------+---------------------+------+-----+---------+-------+ --- | rel_channel | bigint(20) unsigned | NO | PRI | NULL | | --- | rel_user | bigint(20) unsigned | NO | PRI | NULL | | --- | rel_last_message_id | bigint(20) unsigned | YES | | NULL | | --- | new_messages_count | int(10) unsigned | NO | | 0 | | --- +---------------------+---------------------+------+-----+---------+-------+ - --- Prefill with data -INSERT INTO channel_views (rel_channel, rel_user, rel_last_message_id) - SELECT cm.rel_channel, cm.rel_user, max(m.ID) - FROM channel_members AS cm INNER JOIN messages AS m ON (m.rel_channel = cm.rel_channel) - GROUP BY cm.rel_channel, cm.rel_user; - diff --git a/messaging/db/schema/mysql/20181013080000.replies.up.sql b/messaging/db/schema/mysql/20181013080000.replies.up.sql deleted file mode 100644 index 958d00ffe..000000000 --- a/messaging/db/schema/mysql/20181013080000.replies.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE messages CHANGE reply_to reply_to BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE messages ADD replies INT UNSIGNED NOT NULL DEFAULT 0; diff --git a/messaging/db/schema/mysql/20181101080000.pins_and_reactions.up.sql b/messaging/db/schema/mysql/20181101080000.pins_and_reactions.up.sql deleted file mode 100644 index 1d1a92531..000000000 --- a/messaging/db/schema/mysql/20181101080000.pins_and_reactions.up.sql +++ /dev/null @@ -1,14 +0,0 @@ -DROP TABLE channel_pins; -DROP TABLE reactions; - -CREATE TABLE message_flags ( - id BIGINT UNSIGNED NOT NULL, - rel_channel BIGINT UNSIGNED NOT NULL, - rel_message BIGINT UNSIGNED NOT NULL, - rel_user BIGINT UNSIGNED NOT NULL, - flag TEXT, - - created_at DATETIME NOT NULL DEFAULT NOW(), - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/messaging/db/schema/mysql/20181107080000.mentions.up.sql b/messaging/db/schema/mysql/20181107080000.mentions.up.sql deleted file mode 100644 index 1a62c28c6..000000000 --- a/messaging/db/schema/mysql/20181107080000.mentions.up.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE mentions ( - id BIGINT UNSIGNED NOT NULL, - rel_channel BIGINT UNSIGNED NOT NULL, - rel_message BIGINT UNSIGNED NOT NULL, - rel_user BIGINT UNSIGNED NOT NULL, - rel_mentioned_by BIGINT UNSIGNED NOT NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE INDEX lookup_mentions ON mentions (rel_mentioned_by) diff --git a/messaging/db/schema/mysql/20181115080000.unreads.up.sql b/messaging/db/schema/mysql/20181115080000.unreads.up.sql deleted file mode 100644 index be7d52800..000000000 --- a/messaging/db/schema/mysql/20181115080000.unreads.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE channel_views RENAME TO unreads; - -ALTER TABLE unreads ADD rel_reply_to BIGINT UNSIGNED NOT NULL AFTER rel_channel; -ALTER TABLE unreads CHANGE rel_channel rel_channel BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE unreads CHANGE rel_user rel_user BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE unreads CHANGE rel_last_message_id rel_last_message BIGINT UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE unreads CHANGE new_messages_count count INT UNSIGNED NOT NULL DEFAULT 0; - diff --git a/messaging/db/schema/mysql/20181124173028.remove_events_tables.up.sql b/messaging/db/schema/mysql/20181124173028.remove_events_tables.up.sql deleted file mode 100644 index de9a85dfe..000000000 --- a/messaging/db/schema/mysql/20181124173028.remove_events_tables.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE event_queue; -DROP TABLE event_queue_synced; \ No newline at end of file diff --git a/messaging/db/schema/mysql/20181205153145.messages-to-utf8mb4.up.sql b/messaging/db/schema/mysql/20181205153145.messages-to-utf8mb4.up.sql deleted file mode 100644 index 57cbb3ebf..000000000 --- a/messaging/db/schema/mysql/20181205153145.messages-to-utf8mb4.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table messages convert to character set utf8mb4 collate utf8mb4_unicode_ci; \ No newline at end of file diff --git a/messaging/db/schema/mysql/20190122191150.membership-flags.up.sql b/messaging/db/schema/mysql/20190122191150.membership-flags.up.sql deleted file mode 100644 index fdbdb36b7..000000000 --- a/messaging/db/schema/mysql/20190122191150.membership-flags.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE channel_members ADD flag ENUM ('pinned', 'hidden', 'ignored', '') NOT NULL DEFAULT '' AFTER `type`; diff --git a/messaging/db/schema/mysql/20190206112022.prefix-tables.up.sql b/messaging/db/schema/mysql/20190206112022.prefix-tables.up.sql deleted file mode 100644 index 45a08f943..000000000 --- a/messaging/db/schema/mysql/20190206112022.prefix-tables.up.sql +++ /dev/null @@ -1,16 +0,0 @@ --- misc tables - -ALTER TABLE attachments RENAME TO messaging_attachment; -ALTER TABLE mentions RENAME TO messaging_mention; -ALTER TABLE unreads RENAME TO messaging_unread; - --- channel tables - -ALTER TABLE channels RENAME TO messaging_channel; -ALTER TABLE channel_members RENAME TO messaging_channel_member; - --- message tables - -ALTER TABLE messages RENAME TO messaging_message; -ALTER TABLE message_attachment RENAME TO messaging_message_attachment; -ALTER TABLE message_flags RENAME TO messaging_message_flag; diff --git a/messaging/db/schema/mysql/20190326181923.webhook-table.up.sql b/messaging/db/schema/mysql/20190326181923.webhook-table.up.sql deleted file mode 100644 index bfdbd9a67..000000000 --- a/messaging/db/schema/mysql/20190326181923.webhook-table.up.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE TABLE `messaging_webhook` ( - `id` bigint(20) unsigned NOT NULL, - `kind` varchar(8) NOT NULL COMMENT 'Kind: incoming, outgoing', - `token` varchar(255) NOT NULL COMMENT 'Authentication token', - `rel_owner` bigint(20) unsigned NOT NULL COMMENT 'Webhook owner User ID', - `rel_user` bigint(20) unsigned NOT NULL COMMENT 'Webhook message User ID', - `rel_channel` bigint(20) unsigned NOT NULL COMMENT 'Channel ID', - `outgoing_trigger` varchar(32) NOT NULL COMMENT 'Outgoing command trigger', - `outgoing_url` varchar(255) NOT NULL COMMENT 'URL for POST request', - `created_at` datetime NOT NULL, - `updated_at` datetime NULL, - `deleted_at` datetime NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- get webhook by command trigger -ALTER TABLE `messaging_webhook` ADD UNIQUE(`outgoing_trigger`); - --- list webhooks by owner (list your own webhooks) -ALTER TABLE `messaging_webhook` ADD INDEX(`rel_owner`); - --- list webhooks on a channel -ALTER TABLE `messaging_webhook` ADD INDEX(`rel_channel`); diff --git a/messaging/db/schema/mysql/20190526090000.permissions.up.sql b/messaging/db/schema/mysql/20190526090000.permissions.up.sql deleted file mode 100644 index 98924fb95..000000000 --- a/messaging/db/schema/mysql/20190526090000.permissions.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS messaging_permission_rules ( - rel_role BIGINT UNSIGNED NOT NULL, - resource VARCHAR(128) NOT NULL, - operation VARCHAR(128) NOT NULL, - access TINYINT(1) NOT NULL, - - PRIMARY KEY (rel_role, resource, operation) -) ENGINE=InnoDB; diff --git a/messaging/db/schema/mysql/20190623080000.unreads.up.sql b/messaging/db/schema/mysql/20190623080000.unreads.up.sql deleted file mode 100644 index 17a6e08ff..000000000 --- a/messaging/db/schema/mysql/20190623080000.unreads.up.sql +++ /dev/null @@ -1,41 +0,0 @@ -UPDATE `messaging_unread` SET rel_reply_to = 0 WHERE rel_reply_to IS NULL; -ALTER TABLE `messaging_unread` CHANGE COLUMN `rel_reply_to` `rel_reply_to` BIGINT UNSIGNED NOT NULL; -ALTER TABLE `messaging_unread` DROP PRIMARY KEY, ADD PRIMARY KEY(`rel_channel`, `rel_reply_to`, `rel_user`); - --- Add entries for all (unexisting) unreads (channels & threads) -INSERT IGNORE INTO messaging_unread - (rel_channel, rel_reply_to, rel_user) -SELECT DISTINCT cm.rel_channel, msg.id, cm.rel_user - FROM messaging_channel_member AS cm - INNER JOIN messaging_message AS msg ON (cm.rel_channel = msg.rel_channel AND replies > 0) - WHERE NOT EXISTS (SELECT 1 FROM messaging_unread AS u WHERE u.rel_reply_to = msg.id AND u.rel_user = cm.rel_user) - AND msg.rel_user > 0 - -UNION - -SELECT DISTINCT cm.rel_channel, 0, cm.rel_user - FROM messaging_channel_member AS cm - WHERE NOT EXISTS (SELECT 1 FROM messaging_unread AS u WHERE u.rel_channel = cm.rel_channel AND u.rel_user = cm.rel_user) - AND cm.rel_user > 0 -; - - --- Update counters for channel messages -INSERT IGNORE INTO messaging_unread - (rel_channel, rel_reply_to, rel_user, count, rel_last_message) -SELECT u.rel_channel, 0, u.rel_user, COUNT(m.id), u.rel_last_message - FROM messaging_unread AS u - INNER JOIN messaging_message AS m ON (u.rel_channel = m.rel_channel AND m.id > u.rel_last_message) - WHERE u.rel_reply_to = 0 - AND m.reply_to = 0 - GROUP BY u.rel_channel, u.rel_user; - --- Update counters for thread messages - -INSERT IGNORE INTO messaging_unread - (rel_channel, rel_reply_to, rel_user, count, rel_last_message) -SELECT u.rel_channel, rpl.reply_to, u.rel_user, COUNT(rpl.id), u.rel_last_message - FROM messaging_unread AS u - INNER JOIN messaging_message AS rpl ON (u.rel_channel = rpl.rel_channel AND rpl.reply_to = u.rel_reply_to AND rpl.id > u.rel_last_message) - WHERE rpl.replies > 0 AND u.rel_reply_to > 0 - GROUP BY u.rel_channel, rpl.reply_to, u.rel_user; diff --git a/messaging/db/schema/mysql/20190808000000.channel_membership_policy.up.sql b/messaging/db/schema/mysql/20190808000000.channel_membership_policy.up.sql deleted file mode 100644 index fb2356fea..000000000 --- a/messaging/db/schema/mysql/20190808000000.channel_membership_policy.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `messaging_channel` ADD `membership_policy` ENUM ('featured', 'forced', '') NOT NULL DEFAULT '' AFTER `type`; diff --git a/messaging/db/schema/mysql/20191008125405.settings.up.sql b/messaging/db/schema/mysql/20191008125405.settings.up.sql deleted file mode 100644 index 7f27ad421..000000000 --- a/messaging/db/schema/mysql/20191008125405.settings.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE IF NOT EXISTS `messaging_settings` ( - rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings', - name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys', - value JSON COMMENT 'Setting value', - - updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated', - updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value', - - PRIMARY KEY (name, rel_owner) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/messaging/db/schema/mysql/20200602090000.webhook-drop.up.sql b/messaging/db/schema/mysql/20200602090000.webhook-drop.up.sql deleted file mode 100644 index ad16bde80..000000000 --- a/messaging/db/schema/mysql/20200602090000.webhook-drop.up.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `messaging_webhook`; diff --git a/messaging/db/schema/mysql/migrations.sql b/messaging/db/schema/mysql/migrations.sql deleted file mode 100644 index 4461b6183..000000000 --- a/messaging/db/schema/mysql/migrations.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS `migrations` ( - `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...', - `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql', - `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file', - `status` TEXT NOT NULL COMMENT 'ok or full error message', - PRIMARY KEY (`project`,`filename`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - diff --git a/messaging/db/schema/mysql/new.sh b/messaging/db/schema/mysql/new.sh deleted file mode 100755 index 5530da8dc..000000000 --- a/messaging/db/schema/mysql/new.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -touch $(date +%Y%m%d%H%M%S).up.sql \ No newline at end of file diff --git a/messaging/db/types.go b/messaging/db/types.go deleted file mode 100644 index 8cd781a53..000000000 --- a/messaging/db/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package db - -type migration struct { - Project string `db:"project"` - Filename string `db:"filename"` - StatementIndex int `db:"statement_index"` - Status string `db:"status"` -} diff --git a/system/db/migrate.go b/system/db/migrate.go deleted file mode 100644 index d7a91cfab..000000000 --- a/system/db/migrate.go +++ /dev/null @@ -1,117 +0,0 @@ -package db - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "sort" - "strings" - - "github.com/goware/statik/fs" - "github.com/pkg/errors" - "github.com/titpetric/factory" - "go.uber.org/zap" - - "github.com/cortezaproject/corteza-server/system/db/mysql" -) - -func statements(contents []byte, err error) ([]string, error) { - if err != nil { - return []string{}, err - } - return regexp.MustCompilePOSIX(";$").Split(string(contents), -1), nil -} - -func Migrate(db *factory.DB, log *zap.Logger) error { - log = log.Named("database.migrations") - - statikFS, err := fs.New(mysql.Asset) - if err != nil { - return errors.Wrap(err, "error creating statik filesystem") - } - - var files []string - - fn := func(filename string, info os.FileInfo, err error) error { - _ = err - matched, err := filepath.Match("/*.up.sql", filename) - if matched { - files = append(files, filename) - } - - return err - } - - if err := fs.Walk(statikFS, "/", fn); err != nil { - return errors.Wrap(err, "error when listing files for migrations") - } - - sort.Strings(files) - - if len(files) == 0 { - return errors.New("no files encoded for migration, need at least one SQL file") - } - - migrate := func(filename string, useLog bool) error { - status := migration{ - Project: "system", - Filename: filename, - } - if useLog { - if err := db.Get(&status, "select * from migrations where project=? and filename=?", status.Project, status.Filename); err != nil { - return err - } - if status.Status == "ok" { - return nil - } - } - - up := func() error { - stmts, err := statements(fs.ReadFile(statikFS, filename)) - if err != nil { - return errors.Wrap(err, fmt.Sprintf("error reading migration %s", filename)) - } - - log.Debug("Running migration", zap.String("filename", filename)) - for idx, query := range stmts { - if strings.TrimSpace(query) != "" && idx >= status.StatementIndex { - status.StatementIndex = idx - if _, err := db.Exec(query); err != nil { - log.Debug("migration error ", zap.String("filename", filename), zap.Error(err)) - return err - } - } - } - - status.Status = "ok" - return nil - } - - err := db.Transaction(up) - if err != nil { - status.Status = err.Error() - } - if useLog { - if err := db.Replace("migrations", status); err != nil { - return errors.Wrap(err, "migration update failed") - } - } - return err - } - - if err := migrate("/migrations.sql", false); err != nil { - return err - } - - db.Exec("LOCK TABLE migrations WRITE;") - defer db.Exec("UNLOCK TABLES") - - for _, filename := range files { - if err := migrate(filename, true); err != nil { - return err - } - } - - return nil -} diff --git a/system/db/mysql/static.go b/system/db/mysql/static.go deleted file mode 100644 index 9a9b3c100..000000000 --- a/system/db/mysql/static.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by statik. DO NOT EDIT. - -// Package contains static assets. -package mysql - -var Asset = "PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00 \x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8-- all known organisations (crust instances) and our relation towards them\nCREATE TABLE organisations (\n id BIGINT UNSIGNED NOT NULL,\n fqn TEXT NOT NULL, -- fully qualified name of the organisation\n name TEXT NOT NULL, -- display name of the organisation\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n archived_at DATETIME NULL,\n deleted_at DATETIME NULL, -- organisation soft delete\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE settings (\n name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys',\n value TEXT COMMENT 'Setting value',\n\n PRIMARY KEY (name)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n-- Keeps all known users, home and external organisation\n-- changes are stored in audit log\nCREATE TABLE users (\n id BIGINT UNSIGNED NOT NULL,\n email TEXT NOT NULL,\n username TEXT NOT NULL,\n password TEXT NOT NULL,\n name TEXT NOT NULL,\n handle TEXT NOT NULL,\n meta JSON NOT NULL,\n satosa_id CHAR(36) NULL,\n\n rel_organisation BIGINT UNSIGNED NOT NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n suspended_at DATETIME NULL,\n deleted_at DATETIME NULL, -- user soft delete\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE UNIQUE INDEX uid_satosa ON users (satosa_id);\n\n-- Keeps all known teams\nCREATE TABLE teams (\n id BIGINT UNSIGNED NOT NULL,\n name TEXT NOT NULL, -- display name of the team\n handle TEXT NOT NULL, -- team handle string\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n archived_at DATETIME NULL,\n deleted_at DATETIME NULL, -- team soft delete\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n-- Keeps team memberships\nCREATE TABLE team_members (\n rel_team BIGINT UNSIGNED NOT NULL REFERENCES organisation(id),\n rel_user BIGINT UNSIGNED NOT NULL,\n\n PRIMARY KEY (rel_team, rel_user)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\xedzU\x8am \x00\x00m \x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00.\x00 \x0020181124181811.rename_and_prefix_tables.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE teams RENAME TO sys_team;\nALTER TABLE organisations RENAME TO sys_organisation;\nALTER TABLE team_members RENAME TO sys_team_member;\nALTER TABLE users RENAME TO sys_user;PK\x07\x08\xf2\xc4\x87\xe8\xb5\x00\x00\x00\xb5\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00-\x00 \x0020181125100429.add_user_kind_and_owner.up.sqlUT\x05\x00\x01\x80Cm8# add field to manage user type (bot support)\nALTER TABLE `sys_user` ADD `kind` VARCHAR(8) NOT NULL DEFAULT '' AFTER `handle`;\n\n# add field to manage \"ownership\" (get all bots created by user)\nALTER TABLE `sys_user` ADD `rel_user_id` BIGINT UNSIGNED NOT NULL AFTER `rel_organisation`, ADD INDEX (`rel_user_id`);\nPK\x07\x089\xa0\xdat8\x01\x00\x008\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00-\x00 \x0020181125153544.satosa_index_not_unique.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `sys_user` DROP INDEX `uid_satosa`, ADD INDEX `uid_satosa` (`satosa_id`) USING BTREE;PK\x07\x08\x0d\xf9\xd3ga\x00\x00\x00a\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020181208140000.credentials.up.sqlUT\x05\x00\x01\x80Cm8-- Keeps all known users, home and external organisation\n-- changes are stored in audit log\nCREATE TABLE sys_credentials (\n id BIGINT UNSIGNED NOT NULL,\n rel_owner BIGINT UNSIGNED NOT NULL REFERENCES sys_users(id),\n label TEXT NOT NULL COMMENT 'something we can differentiate credentials by',\n kind VARCHAR(128) NOT NULL COMMENT 'hash, facebook, gplus, github, linkedin ...',\n credentials TEXT NOT NULL COMMENT 'crypted/hashed passwords, secrets, social profile ID',\n meta JSON NOT NULL,\n expires_at DATETIME NULL,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL, -- user soft delete\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE INDEX idx_owner ON sys_credentials (rel_owner);\nPK\x07\x08f\x1f\x08\xd0\x9a\x03\x00\x00\x9a\x03\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)\x00 \x0020190103203201.users-password-null.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `sys_user` MODIFY `password` TEXT NULL;\nPK\x07\x080V\x13\x0f4\x00\x00\x004\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00 \x0020190116102104.rules.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE `sys_rules` (\n `rel_team` BIGINT UNSIGNED NOT NULL,\n `resource` VARCHAR(128) NOT NULL,\n `operation` VARCHAR(128) NOT NULL,\n `value` TINYINT(1) NOT NULL,\n\n PRIMARY KEY (`rel_team`, `resource`, `operation`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\x05\x10[\x91\x05\x01\x00\x00\x05\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)\x00 \x0020190221001051.rename-team-to-role.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE sys_team RENAME TO sys_role;\nALTER TABLE sys_team_member RENAME TO sys_role_member;\n\nALTER TABLE `sys_role_member` CHANGE COLUMN `rel_team` `rel_role` BIGINT UNSIGNED NOT NULL;\nALTER TABLE `sys_rules` CHANGE COLUMN `rel_team` `rel_role` BIGINT UNSIGNED NOT NULL;\nPK\x07\x08s-\x98\xd0\x13\x01\x00\x00\x13\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x00 \x0020190226160000.system_roles_and_rules.up.sqlUT\x05\x00\x01\x80Cm8REPLACE INTO `sys_role` (`id`, `name`, `handle`) VALUES\n (1, 'Everyone', 'everyone'),\n (2, 'Administrators', 'admins');\n\nPK\x07\x08\x06RHi{\x00\x00\x00{\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\"\x00 \x0020190306205033.applications.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE sys_application (\n id BIGINT UNSIGNED NOT NULL,\n rel_owner BIGINT UNSIGNED NOT NULL REFERENCES sys_users(id),\n name TEXT NOT NULL COMMENT 'something we can differentiate application by',\n enabled BOOL NOT NULL,\n\n unify JSON NULL COMMENT 'unify specific settings',\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL, -- user soft delete\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n\nREPLACE INTO `sys_application` (`id`, `name`, `enabled`, `rel_owner`, `unify`) VALUES\n( 1, 'Crust Messaging', true, 0,\n '{\"logo\": \"/applications/crust.jpg\", \"icon\": \"/applications/crust_favicon.png\", \"url\": \"/messaging/\", \"listed\": true}'\n),\n( 2, 'Crust CRM', true, 0,\n '{\"logo\": \"/applications/crust.jpg\", \"icon\": \"/applications/crust_favicon.png\", \"url\": \"/crm/\", \"listed\": true}'\n),\n( 3, 'Crust Admin Area', true, 0,\n '{\"logo\": \"/applications/crust.jpg\", \"icon\": \"/applications/crust_favicon.png\", \"url\": \"/admin/\", \"listed\": true}'\n),\n( 4, 'Corteza Jitsi Bridge', true, 0,\n '{\"logo\": \"/applications/jitsi.png\", \"icon\": \"/applications/jitsi_icon.png\", \"url\": \"/bridge/jitsi/\", \"listed\": true}'\n),\n( 5, 'Google Maps', true, 0,\n '{\"logo\": \"/applications/google_maps.png\", \"icon\": \"/applications/google_maps_icon.png\", \"url\": \"/bridge/google-maps/\", \"listed\": true}'\n);\n\nPK\x07\x08Oi\xd5\xd3\xc6\x05\x00\x00\xc6\x05\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00 \x0020190326122000.settings.up.sqlUT\x05\x00\x01\x80Cm8DROP TABLE IF EXISTS `settings`;\n\nCREATE TABLE IF NOT EXISTS `sys_settings` (\n rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings',\n name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys',\n value JSON COMMENT 'Setting value',\n\n updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated',\n updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value',\n\n PRIMARY KEY (name, rel_owner)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08`\xcb\x1b\x81t\x02\x00\x00t\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190403113201.users-cleanup.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `sys_user` DROP `password`;\nALTER TABLE `sys_user` DROP `satosa_id`;\nALTER TABLE `sys_credentials` ADD `last_used_at` DATETIME NULL;\nPK\x07\x088\x92\x0fs\x91\x00\x00\x00\x91\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00 \x0020190405090000.internal-auth.up.sqlUT\x05\x00\x01\x80Cm8ALTER TABLE `sys_user` ADD `email_confirmed` BOOLEAN NOT NULL DEFAULT FALSE;\nPK\x07\x08\x8fQs\x8cM\x00\x00\x00M\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020190506090000.compose-app.up.sqlUT\x05\x00\x01\x80Cm8UPDATE `sys_application`\n SET `name` = 'Crust Compose',\n `unify` = '{\"logo\": \"/applications/default_logo.jpg\", \"icon\": \"/applications/default_icon.png\", \"url\": \"/compose/\", \"listed\": true}'\n WHERE id = 2;\nPK\x07\x089\x0b\xb8\xf9\xd6\x00\x00\x00\xd6\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00 \x0020190506090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS sys_permission_rules (\n rel_role BIGINT UNSIGNED NOT NULL,\n resource VARCHAR(128) NOT NULL,\n operation VARCHAR(128) NOT NULL,\n access TINYINT(1) NOT NULL,\n\n PRIMARY KEY (rel_role, resource, operation)\n) ENGINE=InnoDB;\n\nCREATE TABLE IF NOT EXISTS messaging_permission_rules (\n rel_role BIGINT UNSIGNED NOT NULL,\n resource VARCHAR(128) NOT NULL,\n operation VARCHAR(128) NOT NULL,\n access TINYINT(1) NOT NULL,\n\n PRIMARY KEY (rel_role, resource, operation)\n) ENGINE=InnoDB;\n\nCREATE TABLE IF NOT EXISTS compose_permission_rules (\n rel_role BIGINT UNSIGNED NOT NULL,\n resource VARCHAR(128) NOT NULL,\n operation VARCHAR(128) NOT NULL,\n access TINYINT(1) NOT NULL,\n\n PRIMARY KEY (rel_role, resource, operation)\n) ENGINE=InnoDB;\n\nREPLACE sys_permission_rules\n (rel_role, resource, operation, access)\n SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'system%';\n\nREPLACE compose_permission_rules\n (rel_role, resource, operation, access)\n SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'compose%';\n\nREPLACE messaging_permission_rules\n (rel_role, resource, operation, access)\n SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'messaging%';\n\nDROP TABLE sys_rules;\nPK\x07\x08\x08\xd4\xe0+e\x05\x00\x00e\x05\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x00 \x0020190826085348.migrate-gplus-google.up.sqlUT\x05\x00\x01\x80Cm8/* migrates existing credentials */\nUPDATE sys_credentials SET kind = 'google' WHERE kind = 'gplus';\n\n/* migrates existing settings. */\nUPDATE sys_settings SET name = REPLACE(name, '.gplus.', '.google.') WHERE name LIKE 'auth.external.providers.gplus.%';\nPK\x07\x08<\xac\xedE\xff\x00\x00\x00\xff\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x0020190902080000.automation.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS sys_automation_script (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `rel_namespace` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'For compatibility only, not used',\n `name` VARCHAR(64) NOT NULL DEFAULT 'unnamed' COMMENT 'The name of the script',\n `source` TEXT NOT NULL COMMENT 'Source code for the script',\n `source_ref` VARCHAR(200) NOT NULL COMMENT 'Where is the script located (if remote)',\n `async` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Do we run this script asynchronously?',\n `rel_runner` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who is running the script? 0 for invoker',\n `run_in_ua` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Run this script inside user-agent environment',\n `timeout` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Any explicit timeout set for this script (milliseconds)?',\n `critical` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is it critical that this script is executed successfully',\n `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is this script enabled?',\n\n `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `updated_at` DATETIME NULL DEFAULT NULL,\n `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `deleted_at` DATETIME NULL DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE IF NOT EXISTS sys_automation_trigger (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `rel_script` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Script that is triggered',\n\n `resource` VARCHAR(128) NOT NULL COMMENT 'Resource triggering the event',\n `event` VARCHAR(128) NOT NULL COMMENT 'Event triggered',\n `event_condition`\n TEXT NOT NULL COMMENT 'Trigger condition',\n `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Trigger enabled?',\n\n `weight` INT NOT NULL DEFAULT 0,\n\n `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `updated_at` DATETIME NULL DEFAULT NULL,\n `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `deleted_at` DATETIME NULL DEFAULT NULL,\n\n CONSTRAINT `fk_sys_automation_script` FOREIGN KEY (`rel_script`) REFERENCES `sys_automation_script` (`id`),\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\xac\xbb\x1b\x07i\x0b\x00\x00i\x0b\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00 \x0020190924093443.reminders.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS sys_reminder (\n `id` BIGINT(20) UNSIGNED NOT NULL,\n `resource` VARCHAR(128) NOT NULL COMMENT 'Resource, that this reminder is bound to',\n `payload` JSON NOT NULL COMMENT 'Payload for this reminder',\n `snooze_count` INT NOT NULL DEFAULT 0 COMMENT 'Number of times this reminder was snoozed',\n\n `assigned_to` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Assignee for this reminder',\n `assigned_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'User that assigned this reminder',\n `assigned_at` DATETIME NOT NULL COMMENT 'When the reminder was assigned',\n\n `dismissed_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'User that dismissed this reminder',\n `dismissed_at` DATETIME NULL DEFAULT NULL COMMENT 'Time the reminder was dismissed',\n\n `remind_at` DATETIME NULL DEFAULT NULL COMMENT 'Time the user should be reminded',\n\n `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `updated_at` DATETIME NULL DEFAULT NULL,\n `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n `deleted_at` DATETIME NULL DEFAULT NULL,\n\n PRIMARY KEY (`id`)\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nPK\x07\x08\n\x10\"\x05X\x06\x00\x00X\x06\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&\x00 \x0020191023213030.settings-cleanup.up.sqlUT\x05\x00\x01\x80Cm8UPDATE `sys_settings` SET `name` = 'general.mail.logo' WHERE `rel_owner` = 0 AND `name` = 'system.defaultLogo';\nUPDATE `sys_settings` SET `name` = 'general.mail.header.en' WHERE `rel_owner` = 0 AND `name` = 'system.mail.header.en';\nUPDATE `sys_settings` SET `name` = 'general.mail.footer.en' WHERE `rel_owner` = 0 AND `name` = 'system.mail.footer.en';\nPK\x07\x08\x98\xd0\xdcje\x01\x00\x00e\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x0020200419125927.attachment.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS sys_attachment (\n id BIGINT UNSIGNED NOT NULL,\n rel_owner BIGINT UNSIGNED NOT NULL,\n\n kind VARCHAR(32) NOT NULL,\n\n url VARCHAR(512),\n preview_url VARCHAR(512),\n\n size INT UNSIGNED,\n mimetype VARCHAR(255),\n name TEXT,\n\n meta JSON,\n\n created_at DATETIME NOT NULL DEFAULT NOW(),\n updated_at DATETIME NULL,\n deleted_at DATETIME NULL,\n\n PRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nPK\x07\x08\xca\xba\xa1l=\x02\x00\x00=\x02\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00 \x0020200508070000.actionlog.up.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS sys_actionlog (\n ts DATETIME NOT NULL DEFAULT NOW(),\n actor_ip_addr VARCHAR(15) NOT NULL,\n actor_id BIGINT UNSIGNED,\n request_origin VARCHAR(32) NOT NULL,\n request_id VARCHAR(64) NOT NULL,\n resource VARCHAR(128) NOT NULL,\n `action` VARCHAR(64) NOT NULL,\n `error` VARCHAR(64) NOT NULL,\n severity SMALLINT NOT NULL,\n description TEXT,\n meta JSON\n\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE INDEX ts ON sys_actionlog (ts DESC);\nCREATE INDEX request_origin ON sys_actionlog (request_origin);\nCREATE INDEX actor_id ON sys_actionlog (actor_id);\nCREATE INDEX resource ON sys_actionlog (resource);\nCREATE INDEX `action` ON sys_actionlog (`action`);\nPK\x07\x08>\xed!\xdbI\x03\x00\x00I\x03\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00 \x00migrations.sqlUT\x05\x00\x01\x80Cm8CREATE TABLE IF NOT EXISTS `migrations` (\n `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...',\n `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql',\n `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file',\n `status` TEXT NOT NULL COMMENT 'ok or full error message',\n PRIMARY KEY (`project`,`filename`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nPK\x07\x08\x0d\xa5T2x\x01\x00\x00x\x01\x00\x00PK\x03\x04\x14\x00\x08\x00\x00\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00 \x00new.shUT\x05\x00\x01\x80Cm8#!/bin/bash\ntouch $(date +%Y%m%d%H%M%S).up.sqlPK\x07\x08s\xd4N*.\x00\x00\x00.\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xedzU\x8am \x00\x00m \x00\x00\x1a\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x0020180704080000.base.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xf2\xc4\x87\xe8\xb5\x00\x00\x00\xb5\x00\x00\x00.\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xbe \x00\x0020181124181811.rename_and_prefix_tables.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(9\xa0\xdat8\x01\x00\x008\x01\x00\x00-\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xd8\n\x00\x0020181125100429.add_user_kind_and_owner.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x0d\xf9\xd3ga\x00\x00\x00a\x00\x00\x00-\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81t\x0c\x00\x0020181125153544.satosa_index_not_unique.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(f\x1f\x08\xd0\x9a\x03\x00\x00\x9a\x03\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x819\x0d\x00\x0020181208140000.credentials.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(0V\x13\x0f4\x00\x00\x004\x00\x00\x00)\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81+\x11\x00\x0020190103203201.users-password-null.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x05\x10[\x91\x05\x01\x00\x00\x05\x01\x00\x00\x1b\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xbf\x11\x00\x0020190116102104.rules.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(s-\x98\xd0\x13\x01\x00\x00\x13\x01\x00\x00)\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x16\x13\x00\x0020190221001051.rename-team-to-role.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x06RHi{\x00\x00\x00{\x00\x00\x00,\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x89\x14\x00\x0020190226160000.system_roles_and_rules.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(Oi\xd5\xd3\xc6\x05\x00\x00\xc6\x05\x00\x00\"\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81g\x15\x00\x0020190306205033.applications.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(`\xcb\x1b\x81t\x02\x00\x00t\x02\x00\x00\x1e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x86\x1b\x00\x0020190326122000.settings.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(8\x92\x0fs\x91\x00\x00\x00\x91\x00\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81O\x1e\x00\x0020190403113201.users-cleanup.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x8fQs\x8cM\x00\x00\x00M\x00\x00\x00#\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81:\x1f\x00\x0020190405090000.internal-auth.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(9\x0b\xb8\xf9\xd6\x00\x00\x00\xd6\x00\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xe1\x1f\x00\x0020190506090000.compose-app.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x08\xd4\xe0+e\x05\x00\x00e\x05\x00\x00!\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x0f!\x00\x0020190506090000.permissions.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(<\xac\xedE\xff\x00\x00\x00\xff\x00\x00\x00*\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xcc&\x00\x0020190826085348.migrate-gplus-google.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xac\xbb\x1b\x07i\x0b\x00\x00i\x0b\x00\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81,(\x00\x0020190902080000.automation.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\n\x10\"\x05X\x06\x00\x00X\x06\x00\x00\x1f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xec3\x00\x0020190924093443.reminders.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x98\xd0\xdcje\x01\x00\x00e\x01\x00\x00&\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x9a:\x00\x0020191023213030.settings-cleanup.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\xca\xba\xa1l=\x02\x00\x00=\x02\x00\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\\<\x00\x0020200419125927.attachment.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(>\xed!\xdbI\x03\x00\x00I\x03\x00\x00\x1f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xf0>\x00\x0020200508070000.actionlog.up.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(\x0d\xa5T2x\x01\x00\x00x\x01\x00\x00\x0e\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x8fB\x00\x00migrations.sqlUT\x05\x00\x01\x80Cm8PK\x01\x02\x14\x03\x14\x00\x08\x00\x00\x00\x00\x00!(s\xd4N*.\x00\x00\x00.\x00\x00\x00\x06\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\x81LD\x00\x00new.shUT\x05\x00\x01\x80Cm8PK\x05\x06\x00\x00\x00\x00\x17\x00\x17\x00\xf7\x07\x00\x00\xb7D\x00\x00\x00\x00" diff --git a/system/db/schema/mysql/20180704080000.base.up.sql b/system/db/schema/mysql/20180704080000.base.up.sql deleted file mode 100644 index a982478b6..000000000 --- a/system/db/schema/mysql/20180704080000.base.up.sql +++ /dev/null @@ -1,66 +0,0 @@ --- all known organisations (crust instances) and our relation towards them -CREATE TABLE organisations ( - id BIGINT UNSIGNED NOT NULL, - fqn TEXT NOT NULL, -- fully qualified name of the organisation - name TEXT NOT NULL, -- display name of the organisation - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - archived_at DATETIME NULL, - deleted_at DATETIME NULL, -- organisation soft delete - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE settings ( - name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys', - value TEXT COMMENT 'Setting value', - - PRIMARY KEY (name) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Keeps all known users, home and external organisation --- changes are stored in audit log -CREATE TABLE users ( - id BIGINT UNSIGNED NOT NULL, - email TEXT NOT NULL, - username TEXT NOT NULL, - password TEXT NOT NULL, - name TEXT NOT NULL, - handle TEXT NOT NULL, - meta JSON NOT NULL, - satosa_id CHAR(36) NULL, - - rel_organisation BIGINT UNSIGNED NOT NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - suspended_at DATETIME NULL, - deleted_at DATETIME NULL, -- user soft delete - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE UNIQUE INDEX uid_satosa ON users (satosa_id); - --- Keeps all known teams -CREATE TABLE teams ( - id BIGINT UNSIGNED NOT NULL, - name TEXT NOT NULL, -- display name of the team - handle TEXT NOT NULL, -- team handle string - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - archived_at DATETIME NULL, - deleted_at DATETIME NULL, -- team soft delete - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Keeps team memberships -CREATE TABLE team_members ( - rel_team BIGINT UNSIGNED NOT NULL REFERENCES organisation(id), - rel_user BIGINT UNSIGNED NOT NULL, - - PRIMARY KEY (rel_team, rel_user) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/system/db/schema/mysql/20181124181811.rename_and_prefix_tables.up.sql b/system/db/schema/mysql/20181124181811.rename_and_prefix_tables.up.sql deleted file mode 100644 index c5d6c2810..000000000 --- a/system/db/schema/mysql/20181124181811.rename_and_prefix_tables.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE teams RENAME TO sys_team; -ALTER TABLE organisations RENAME TO sys_organisation; -ALTER TABLE team_members RENAME TO sys_team_member; -ALTER TABLE users RENAME TO sys_user; \ No newline at end of file diff --git a/system/db/schema/mysql/20181125100429.add_user_kind_and_owner.up.sql b/system/db/schema/mysql/20181125100429.add_user_kind_and_owner.up.sql deleted file mode 100644 index 794d9f1c6..000000000 --- a/system/db/schema/mysql/20181125100429.add_user_kind_and_owner.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -# add field to manage user type (bot support) -ALTER TABLE `sys_user` ADD `kind` VARCHAR(8) NOT NULL DEFAULT '' AFTER `handle`; - -# add field to manage "ownership" (get all bots created by user) -ALTER TABLE `sys_user` ADD `rel_user_id` BIGINT UNSIGNED NOT NULL AFTER `rel_organisation`, ADD INDEX (`rel_user_id`); diff --git a/system/db/schema/mysql/20181125153544.satosa_index_not_unique.up.sql b/system/db/schema/mysql/20181125153544.satosa_index_not_unique.up.sql deleted file mode 100644 index 129853bfb..000000000 --- a/system/db/schema/mysql/20181125153544.satosa_index_not_unique.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `sys_user` DROP INDEX `uid_satosa`, ADD INDEX `uid_satosa` (`satosa_id`) USING BTREE; \ No newline at end of file diff --git a/system/db/schema/mysql/20181208140000.credentials.up.sql b/system/db/schema/mysql/20181208140000.credentials.up.sql deleted file mode 100644 index 0e4e60e7e..000000000 --- a/system/db/schema/mysql/20181208140000.credentials.up.sql +++ /dev/null @@ -1,19 +0,0 @@ --- Keeps all known users, home and external organisation --- changes are stored in audit log -CREATE TABLE sys_credentials ( - id BIGINT UNSIGNED NOT NULL, - rel_owner BIGINT UNSIGNED NOT NULL REFERENCES sys_users(id), - label TEXT NOT NULL COMMENT 'something we can differentiate credentials by', - kind VARCHAR(128) NOT NULL COMMENT 'hash, facebook, gplus, github, linkedin ...', - credentials TEXT NOT NULL COMMENT 'crypted/hashed passwords, secrets, social profile ID', - meta JSON NOT NULL, - expires_at DATETIME NULL, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, -- user soft delete - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE INDEX idx_owner ON sys_credentials (rel_owner); diff --git a/system/db/schema/mysql/20190103203201.users-password-null.up.sql b/system/db/schema/mysql/20190103203201.users-password-null.up.sql deleted file mode 100644 index dc2c50961..000000000 --- a/system/db/schema/mysql/20190103203201.users-password-null.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `sys_user` MODIFY `password` TEXT NULL; diff --git a/system/db/schema/mysql/20190116102104.rules.up.sql b/system/db/schema/mysql/20190116102104.rules.up.sql deleted file mode 100644 index 0b2295144..000000000 --- a/system/db/schema/mysql/20190116102104.rules.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `sys_rules` ( - `rel_team` BIGINT UNSIGNED NOT NULL, - `resource` VARCHAR(128) NOT NULL, - `operation` VARCHAR(128) NOT NULL, - `value` TINYINT(1) NOT NULL, - - PRIMARY KEY (`rel_team`, `resource`, `operation`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/system/db/schema/mysql/20190221001051.rename-team-to-role.up.sql b/system/db/schema/mysql/20190221001051.rename-team-to-role.up.sql deleted file mode 100644 index 89f1c4c90..000000000 --- a/system/db/schema/mysql/20190221001051.rename-team-to-role.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE sys_team RENAME TO sys_role; -ALTER TABLE sys_team_member RENAME TO sys_role_member; - -ALTER TABLE `sys_role_member` CHANGE COLUMN `rel_team` `rel_role` BIGINT UNSIGNED NOT NULL; -ALTER TABLE `sys_rules` CHANGE COLUMN `rel_team` `rel_role` BIGINT UNSIGNED NOT NULL; diff --git a/system/db/schema/mysql/20190226160000.system_roles_and_rules.up.sql b/system/db/schema/mysql/20190226160000.system_roles_and_rules.up.sql deleted file mode 100644 index 7cdac8d81..000000000 --- a/system/db/schema/mysql/20190226160000.system_roles_and_rules.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -REPLACE INTO `sys_role` (`id`, `name`, `handle`) VALUES - (1, 'Everyone', 'everyone'), - (2, 'Administrators', 'admins'); - diff --git a/system/db/schema/mysql/20190306205033.applications.up.sql b/system/db/schema/mysql/20190306205033.applications.up.sql deleted file mode 100644 index bf72ba811..000000000 --- a/system/db/schema/mysql/20190306205033.applications.up.sql +++ /dev/null @@ -1,33 +0,0 @@ -CREATE TABLE sys_application ( - id BIGINT UNSIGNED NOT NULL, - rel_owner BIGINT UNSIGNED NOT NULL REFERENCES sys_users(id), - name TEXT NOT NULL COMMENT 'something we can differentiate application by', - enabled BOOL NOT NULL, - - unify JSON NULL COMMENT 'unify specific settings', - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, -- user soft delete - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - -REPLACE INTO `sys_application` (`id`, `name`, `enabled`, `rel_owner`, `unify`) VALUES -( 1, 'Crust Messaging', true, 0, - '{"logo": "/applications/crust.jpg", "icon": "/applications/crust_favicon.png", "url": "/messaging/", "listed": true}' -), -( 2, 'Crust CRM', true, 0, - '{"logo": "/applications/crust.jpg", "icon": "/applications/crust_favicon.png", "url": "/crm/", "listed": true}' -), -( 3, 'Crust Admin Area', true, 0, - '{"logo": "/applications/crust.jpg", "icon": "/applications/crust_favicon.png", "url": "/admin/", "listed": true}' -), -( 4, 'Corteza Jitsi Bridge', true, 0, - '{"logo": "/applications/jitsi.png", "icon": "/applications/jitsi_icon.png", "url": "/bridge/jitsi/", "listed": true}' -), -( 5, 'Google Maps', true, 0, - '{"logo": "/applications/google_maps.png", "icon": "/applications/google_maps_icon.png", "url": "/bridge/google-maps/", "listed": true}' -); - diff --git a/system/db/schema/mysql/20190326122000.settings.up.sql b/system/db/schema/mysql/20190326122000.settings.up.sql deleted file mode 100644 index 9e06d8b05..000000000 --- a/system/db/schema/mysql/20190326122000.settings.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -DROP TABLE IF EXISTS `settings`; - -CREATE TABLE IF NOT EXISTS `sys_settings` ( - rel_owner BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Value owner, 0 for global settings', - name VARCHAR(200) NOT NULL COMMENT 'Unique set of setting keys', - value JSON COMMENT 'Setting value', - - updated_at DATETIME NOT NULL DEFAULT NOW() COMMENT 'When was the value updated', - updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who created/updated the value', - - PRIMARY KEY (name, rel_owner) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/system/db/schema/mysql/20190403113201.users-cleanup.up.sql b/system/db/schema/mysql/20190403113201.users-cleanup.up.sql deleted file mode 100644 index b02326c51..000000000 --- a/system/db/schema/mysql/20190403113201.users-cleanup.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `sys_user` DROP `password`; -ALTER TABLE `sys_user` DROP `satosa_id`; -ALTER TABLE `sys_credentials` ADD `last_used_at` DATETIME NULL; diff --git a/system/db/schema/mysql/20190405090000.internal-auth.up.sql b/system/db/schema/mysql/20190405090000.internal-auth.up.sql deleted file mode 100644 index db3baea3c..000000000 --- a/system/db/schema/mysql/20190405090000.internal-auth.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `sys_user` ADD `email_confirmed` BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/system/db/schema/mysql/20190506090000.compose-app.up.sql b/system/db/schema/mysql/20190506090000.compose-app.up.sql deleted file mode 100644 index c35687524..000000000 --- a/system/db/schema/mysql/20190506090000.compose-app.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE `sys_application` - SET `name` = 'Crust Compose', - `unify` = '{"logo": "/applications/default_logo.jpg", "icon": "/applications/default_icon.png", "url": "/compose/", "listed": true}' - WHERE id = 2; diff --git a/system/db/schema/mysql/20190506090000.permissions.up.sql b/system/db/schema/mysql/20190506090000.permissions.up.sql deleted file mode 100644 index 8b854c7e3..000000000 --- a/system/db/schema/mysql/20190506090000.permissions.up.sql +++ /dev/null @@ -1,40 +0,0 @@ -CREATE TABLE IF NOT EXISTS sys_permission_rules ( - rel_role BIGINT UNSIGNED NOT NULL, - resource VARCHAR(128) NOT NULL, - operation VARCHAR(128) NOT NULL, - access TINYINT(1) NOT NULL, - - PRIMARY KEY (rel_role, resource, operation) -) ENGINE=InnoDB; - -CREATE TABLE IF NOT EXISTS messaging_permission_rules ( - rel_role BIGINT UNSIGNED NOT NULL, - resource VARCHAR(128) NOT NULL, - operation VARCHAR(128) NOT NULL, - access TINYINT(1) NOT NULL, - - PRIMARY KEY (rel_role, resource, operation) -) ENGINE=InnoDB; - -CREATE TABLE IF NOT EXISTS compose_permission_rules ( - rel_role BIGINT UNSIGNED NOT NULL, - resource VARCHAR(128) NOT NULL, - operation VARCHAR(128) NOT NULL, - access TINYINT(1) NOT NULL, - - PRIMARY KEY (rel_role, resource, operation) -) ENGINE=InnoDB; - -REPLACE sys_permission_rules - (rel_role, resource, operation, access) - SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'system%'; - -REPLACE compose_permission_rules - (rel_role, resource, operation, access) - SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'compose%'; - -REPLACE messaging_permission_rules - (rel_role, resource, operation, access) - SELECT rel_role, resource, operation, `value` - 1 FROM sys_rules WHERE resource LIKE 'messaging%'; - -DROP TABLE sys_rules; diff --git a/system/db/schema/mysql/20190826085348.migrate-gplus-google.up.sql b/system/db/schema/mysql/20190826085348.migrate-gplus-google.up.sql deleted file mode 100644 index e76a2aa1b..000000000 --- a/system/db/schema/mysql/20190826085348.migrate-gplus-google.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -/* migrates existing credentials */ -UPDATE sys_credentials SET kind = 'google' WHERE kind = 'gplus'; - -/* migrates existing settings. */ -UPDATE sys_settings SET name = REPLACE(name, '.gplus.', '.google.') WHERE name LIKE 'auth.external.providers.gplus.%'; diff --git a/system/db/schema/mysql/20190902080000.automation.up.sql b/system/db/schema/mysql/20190902080000.automation.up.sql deleted file mode 100644 index dc5c31588..000000000 --- a/system/db/schema/mysql/20190902080000.automation.up.sql +++ /dev/null @@ -1,48 +0,0 @@ -CREATE TABLE IF NOT EXISTS sys_automation_script ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `rel_namespace` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'For compatibility only, not used', - `name` VARCHAR(64) NOT NULL DEFAULT 'unnamed' COMMENT 'The name of the script', - `source` TEXT NOT NULL COMMENT 'Source code for the script', - `source_ref` VARCHAR(200) NOT NULL COMMENT 'Where is the script located (if remote)', - `async` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Do we run this script asynchronously?', - `rel_runner` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Who is running the script? 0 for invoker', - `run_in_ua` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Run this script inside user-agent environment', - `timeout` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Any explicit timeout set for this script (milliseconds)?', - `critical` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is it critical that this script is executed successfully', - `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Is this script enabled?', - - `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `updated_at` DATETIME NULL DEFAULT NULL, - `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `deleted_at` DATETIME NULL DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE IF NOT EXISTS sys_automation_trigger ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `rel_script` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Script that is triggered', - - `resource` VARCHAR(128) NOT NULL COMMENT 'Resource triggering the event', - `event` VARCHAR(128) NOT NULL COMMENT 'Event triggered', - `event_condition` - TEXT NOT NULL COMMENT 'Trigger condition', - `enabled` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'Trigger enabled?', - - `weight` INT NOT NULL DEFAULT 0, - - `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `updated_at` DATETIME NULL DEFAULT NULL, - `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `deleted_at` DATETIME NULL DEFAULT NULL, - - CONSTRAINT `fk_sys_automation_script` FOREIGN KEY (`rel_script`) REFERENCES `sys_automation_script` (`id`), - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/system/db/schema/mysql/20190924093443.reminders.up.sql b/system/db/schema/mysql/20190924093443.reminders.up.sql deleted file mode 100644 index 309512a12..000000000 --- a/system/db/schema/mysql/20190924093443.reminders.up.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE IF NOT EXISTS sys_reminder ( - `id` BIGINT(20) UNSIGNED NOT NULL, - `resource` VARCHAR(128) NOT NULL COMMENT 'Resource, that this reminder is bound to', - `payload` JSON NOT NULL COMMENT 'Payload for this reminder', - `snooze_count` INT NOT NULL DEFAULT 0 COMMENT 'Number of times this reminder was snoozed', - - `assigned_to` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Assignee for this reminder', - `assigned_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'User that assigned this reminder', - `assigned_at` DATETIME NOT NULL COMMENT 'When the reminder was assigned', - - `dismissed_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'User that dismissed this reminder', - `dismissed_at` DATETIME NULL DEFAULT NULL COMMENT 'Time the reminder was dismissed', - - `remind_at` DATETIME NULL DEFAULT NULL COMMENT 'Time the user should be reminded', - - `created_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `updated_at` DATETIME NULL DEFAULT NULL, - `deleted_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, - `deleted_at` DATETIME NULL DEFAULT NULL, - - PRIMARY KEY (`id`) - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/system/db/schema/mysql/20191023213030.settings-cleanup.up.sql b/system/db/schema/mysql/20191023213030.settings-cleanup.up.sql deleted file mode 100644 index 072a24496..000000000 --- a/system/db/schema/mysql/20191023213030.settings-cleanup.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE `sys_settings` SET `name` = 'general.mail.logo' WHERE `rel_owner` = 0 AND `name` = 'system.defaultLogo'; -UPDATE `sys_settings` SET `name` = 'general.mail.header.en' WHERE `rel_owner` = 0 AND `name` = 'system.mail.header.en'; -UPDATE `sys_settings` SET `name` = 'general.mail.footer.en' WHERE `rel_owner` = 0 AND `name` = 'system.mail.footer.en'; diff --git a/system/db/schema/mysql/20200419125927.attachment.up.sql b/system/db/schema/mysql/20200419125927.attachment.up.sql deleted file mode 100644 index 17422a15c..000000000 --- a/system/db/schema/mysql/20200419125927.attachment.up.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE TABLE IF NOT EXISTS sys_attachment ( - id BIGINT UNSIGNED NOT NULL, - rel_owner BIGINT UNSIGNED NOT NULL, - - kind VARCHAR(32) NOT NULL, - - url VARCHAR(512), - preview_url VARCHAR(512), - - size INT UNSIGNED, - mimetype VARCHAR(255), - name TEXT, - - meta JSON, - - created_at DATETIME NOT NULL DEFAULT NOW(), - updated_at DATETIME NULL, - deleted_at DATETIME NULL, - - PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - diff --git a/system/db/schema/mysql/20200508070000.actionlog.up.sql b/system/db/schema/mysql/20200508070000.actionlog.up.sql deleted file mode 100644 index d777de63e..000000000 --- a/system/db/schema/mysql/20200508070000.actionlog.up.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE IF NOT EXISTS sys_actionlog ( - ts DATETIME NOT NULL DEFAULT NOW(), - actor_ip_addr VARCHAR(15) NOT NULL, - actor_id BIGINT UNSIGNED, - request_origin VARCHAR(32) NOT NULL, - request_id VARCHAR(64) NOT NULL, - resource VARCHAR(128) NOT NULL, - `action` VARCHAR(64) NOT NULL, - `error` VARCHAR(64) NOT NULL, - severity SMALLINT NOT NULL, - description TEXT, - meta JSON - -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE INDEX ts ON sys_actionlog (ts DESC); -CREATE INDEX request_origin ON sys_actionlog (request_origin); -CREATE INDEX actor_id ON sys_actionlog (actor_id); -CREATE INDEX resource ON sys_actionlog (resource); -CREATE INDEX `action` ON sys_actionlog (`action`); diff --git a/system/db/schema/mysql/migrations.sql b/system/db/schema/mysql/migrations.sql deleted file mode 100644 index 4461b6183..000000000 --- a/system/db/schema/mysql/migrations.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS `migrations` ( - `project` varchar(16) NOT NULL COMMENT 'sam, crm, ...', - `filename` varchar(255) NOT NULL COMMENT 'yyyymmddHHMMSS.sql', - `statement_index` int(11) NOT NULL COMMENT 'Statement number from SQL file', - `status` TEXT NOT NULL COMMENT 'ok or full error message', - PRIMARY KEY (`project`,`filename`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - diff --git a/system/db/schema/mysql/new.sh b/system/db/schema/mysql/new.sh deleted file mode 100755 index 5530da8dc..000000000 --- a/system/db/schema/mysql/new.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -touch $(date +%Y%m%d%H%M%S).up.sql \ No newline at end of file diff --git a/system/db/types.go b/system/db/types.go deleted file mode 100644 index 8cd781a53..000000000 --- a/system/db/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package db - -type migration struct { - Project string `db:"project"` - Filename string `db:"filename"` - StatementIndex int `db:"statement_index"` - Status string `db:"status"` -}