legion-data 0.1.1 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +98 -72
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +5 -7
  5. data/CHANGELOG.md +7 -0
  6. data/Gemfile.lock +85 -0
  7. data/legion-data.gemspec +3 -6
  8. data/lib/legion/data.rb +51 -33
  9. data/lib/legion/data/connection.rb +55 -19
  10. data/lib/legion/data/migration.rb +7 -20
  11. data/lib/legion/data/migrations/001_add_schema_columns.rb +1 -1
  12. data/lib/legion/data/migrations/002_add_users.rb +17 -0
  13. data/lib/legion/data/migrations/003_add_groups.rb +16 -0
  14. data/lib/legion/data/migrations/004_add_chains.rb +25 -0
  15. data/lib/legion/data/migrations/005_add_envs.rb +24 -0
  16. data/lib/legion/data/migrations/006_add_dcs.rb +24 -0
  17. data/lib/legion/data/migrations/007_add_nodes.rb +26 -0
  18. data/lib/legion/data/migrations/008_add_settings.rb +18 -0
  19. data/lib/legion/data/migrations/009_add_extensions.rb +25 -0
  20. data/lib/legion/data/migrations/010_add_runners.rb +21 -0
  21. data/lib/legion/data/migrations/011_add_functions.rb +29 -0
  22. data/lib/legion/data/migrations/012_add_tasks.rb +28 -0
  23. data/lib/legion/data/migrations/013_add_task_logs.rb +23 -0
  24. data/lib/legion/data/migrations/014_add_relationships.rb +27 -0
  25. data/lib/legion/data/migrations/015_add_default_extensions.rb +24 -0
  26. data/lib/legion/data/migrations/016_change_task_args.rb +7 -0
  27. data/lib/legion/data/migrations/017_add_payload_task.rb +7 -0
  28. data/lib/legion/data/migrations/018_add_migration_column.rb +7 -0
  29. data/lib/legion/data/migrations/019_add_debug_to_relationships.rb +7 -0
  30. data/lib/legion/data/migrations/020_add_delay_debug_to_tasks.rb +8 -0
  31. data/lib/legion/data/model.rb +26 -25
  32. data/lib/legion/data/models/chain.rb +0 -1
  33. data/lib/legion/data/models/datacenter.rb +0 -1
  34. data/lib/legion/data/models/environment.rb +0 -1
  35. data/lib/legion/data/models/extension.rb +11 -0
  36. data/lib/legion/data/models/function.rb +5 -4
  37. data/lib/legion/data/models/group.rb +10 -0
  38. data/lib/legion/data/models/node.rb +1 -1
  39. data/lib/legion/data/models/relationship.rb +1 -1
  40. data/lib/legion/data/models/runner.rb +15 -0
  41. data/lib/legion/data/models/setting.rb +10 -0
  42. data/lib/legion/data/models/task.rb +0 -1
  43. data/lib/legion/data/models/task_log.rb +0 -1
  44. data/lib/legion/data/models/user.rb +10 -0
  45. data/lib/legion/data/settings.rb +68 -0
  46. data/lib/legion/data/version.rb +1 -1
  47. data/sonar-project.properties +12 -0
  48. metadata +38 -89
  49. data/lib/legion/data/connections/base.rb +0 -45
  50. data/lib/legion/data/connections/jdbc.rb +0 -21
  51. data/lib/legion/data/connections/mysql.rb +0 -26
  52. data/lib/legion/data/connections/mysql2.rb +0 -26
  53. data/lib/legion/data/connections/mysql_base.rb +0 -19
  54. data/lib/legion/data/migrations/002_add_chains_table.rb +0 -21
  55. data/lib/legion/data/migrations/003_add_datacenters_table.rb +0 -21
  56. data/lib/legion/data/migrations/004_add_envs_table.rb +0 -21
  57. data/lib/legion/data/migrations/005_add_functions_table.rb +0 -25
  58. data/lib/legion/data/migrations/006_add_namespaces_table.rb +0 -24
  59. data/lib/legion/data/migrations/007_add_nodes_table.rb +0 -22
  60. data/lib/legion/data/migrations/008_add_relationships_table.rb +0 -28
  61. data/lib/legion/data/migrations/009_add_task_logs_table.rb +0 -17
  62. data/lib/legion/data/migrations/010_add_tasks_table.rb +0 -20
  63. data/lib/legion/data/migrations/011_add_users_and_groups.rb +0 -28
  64. data/lib/legion/data/migrations/012_foreign_keys_users_and_groups.rb +0 -42
  65. data/lib/legion/data/migrations/013_function_foreign_keys.rb +0 -10
  66. data/lib/legion/data/migrations/014_nodes_foreign_keys.rb +0 -12
  67. data/lib/legion/data/migrations/015_relationships_foreign_keys.rb +0 -14
  68. data/lib/legion/data/migrations/016_tasks_foreign_keys.rb +0 -22
  69. data/lib/legion/data/migrations/017_add_relationship_to_tasks.rb +0 -14
  70. data/lib/legion/data/models/namespace.rb +0 -12
@@ -2,28 +2,64 @@ require 'sequel'
2
2
 
3
3
  module Legion
4
4
  module Data
5
- class Connection
6
- attr_accessor :database
7
- def initialize(options = {})
8
- options.merge!(default_options) { |_key, v1, _v2| v1 }
9
- return unless options[:auto_connect]
10
-
11
- jruby(options) if RUBY_ENGINE == 'jruby'
12
- mri(options) unless RUBY_ENGINE == 'jruby'
13
- end
5
+ module Connection
6
+ class << self
7
+ attr_accessor :sequel
14
8
 
15
- def default_options
16
- { auto_connect: true }
17
- end
9
+ def adapter
10
+ @adapter ||= RUBY_ENGINE == 'jruby' ? :jdbc : :mysql2
11
+ end
18
12
 
19
- def jruby(_options = {})
20
- require 'legion/data/connections/jdbc'
21
- @database = Legion::Data::Connections::JDBC.new
22
- end
13
+ def setup
14
+ @sequel = if adapter == :mysql2
15
+ ::Sequel.connect(adapter: adapter, **creds_builder)
16
+ else
17
+ ::Sequel.connect("jdbc:mysql://#{creds_builder[:host]}:#{creds_builder[:port]}/#{creds_builder[:database]}?user=#{creds_builder[:username]}&password=#{creds_builder[:password]}&serverTimezone=UTC") # rubocop:disable Layout/LineLength
18
+ end
19
+ Legion::Settings[:data][:connected] = true
20
+ return if Legion::Settings[:data][:connection].nil? || Legion::Settings[:data][:connection][:log].nil?
21
+
22
+ @sequel.logger = Legion::Logging
23
+ @sequel.sql_log_level = Legion::Settings[:data][:connection][:sql_log_level]
24
+ @sequel.log_warn_duration = Legion::Settings[:data][:connection][:log_warn_duration]
25
+ end
26
+
27
+ def shutdown
28
+ @sequel&.disconnect
29
+ Legion::Settings[:data][:connected] = false
30
+ end
31
+
32
+ def creds_builder(final_creds = {})
33
+ final_creds.merge! Legion::Data::Settings.creds
34
+ final_creds.merge! Legion::Settings[:data][:creds] if Legion::Settings[:data][:creds].is_a? Hash
35
+
36
+ if Legion::Settings[:data][:connection][:max_connections].is_a? Integer
37
+ final_creds[:max_connections] = Legion::Settings[:data][:connection][:max_connections]
38
+ end
39
+
40
+ final_creds[:preconnect] = :concurrently if Legion::Settings[:data][:connection][:preconnect]
41
+
42
+ return final_creds if Legion::Settings[:vault].nil?
43
+
44
+ if Legion::Settings[:vault][:connected] && ::Vault.sys.mounts.key?(:database)
45
+ temp_vault_creds = Legion::Crypt.read('database/creds/legion')
46
+ final_creds[:user] = temp_vault_creds[:username]
47
+ final_creds[:password] = temp_vault_creds[:password]
48
+ end
49
+
50
+ final_creds
51
+ end
23
52
 
24
- def mri(_options = {})
25
- require 'legion/data/connections/mysql2'
26
- @database = Legion::Data::Connections::MySQL2.new
53
+ def default_creds
54
+ {
55
+ host: '127.0.0.1',
56
+ port: 3306,
57
+ username: 'legion',
58
+ password: 'legion',
59
+ database: 'legion',
60
+ max_connections: 4
61
+ }
62
+ end
27
63
  end
28
64
  end
29
65
  end
@@ -2,26 +2,13 @@ require 'sequel/extensions/migration'
2
2
 
3
3
  module Legion
4
4
  module Data
5
- class Migration
6
- def initialize(connection, options = {})
7
- options.merge!(default_options) { |_key, v1, _v2| v1 }
8
- migrate(options[:migration_path], connection) if options[:auto_migrate]
9
- end
10
-
11
- def default_options
12
- { auto_migrate: true, migration_path: __dir__ + '/migrations' }
13
- end
14
-
15
- def migrate(path, connection)
16
- Legion::Logging.debug("Running Legion::Data.migrate with path: #{path}")
17
- Sequel::Migrator.run(connection, path)
18
- Legion::Logging.info('Legion::Data finished migrations')
19
- rescue Sequel::Migrator::Error => e
20
- Legion::Logging.error(e.message)
21
- raise e
22
- rescue StandardError => e
23
- Legion::Logging.error(e.message)
24
- raise e unless Legion::Settings[:data][:migrations][:continue_on_fail]
5
+ module Migration
6
+ class << self
7
+ def migrate(connection = Legion::Data.connection, path = "#{__dir__}/migrations", **opts)
8
+ Legion::Settings[:data][:migrations][:version] = Sequel::Migrator.run(connection, path, **opts)
9
+ Legion::Logging.info("Legion::Data::Migration ran successfully to version #{Legion::Settings[:data][:migrations][:version]}") # rubocop:disable Layout/LineLength
10
+ Legion::Settings[:data][:migrations][:ran] = true
11
+ end
25
12
  end
26
13
  end
27
14
  end
@@ -8,7 +8,7 @@ Sequel.migration do
8
8
  end
9
9
 
10
10
  down do
11
- alter_table(:schema) do
11
+ alter_table(:schema_info) do
12
12
  drop_column :catalog
13
13
  drop_column :updated_at
14
14
  drop_column :created_at
@@ -0,0 +1,17 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `users` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `active` tinyint(1) unsigned DEFAULT '1',
6
+ `name` varchar(128) DEFAULT NULL,
7
+ `version` tinyint(5) unsigned NOT NULL DEFAULT '1',
8
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
9
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
10
+ PRIMARY KEY (`id`)
11
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
12
+ end
13
+
14
+ down do
15
+ drop_table :users
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `groups` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) DEFAULT NULL,
6
+ `active` tinyint(1) unsigned DEFAULT '1',
7
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
8
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
9
+ PRIMARY KEY (`id`)
10
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
11
+ end
12
+
13
+ down do
14
+ drop_table :groups
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `chains` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) NOT NULL DEFAULT '',
6
+ `active` tinyint(1) unsigned DEFAULT '1',
7
+ `version` int(11) unsigned NOT NULL DEFAULT '1',
8
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
9
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
10
+ `user_owner` int(11) unsigned DEFAULT NULL,
11
+ `group_owner` int(11) unsigned DEFAULT NULL,
12
+ PRIMARY KEY (`id`),
13
+ UNIQUE KEY `name` (`name`),
14
+ KEY `active` (`active`),
15
+ KEY `chains_user_owner` (`user_owner`),
16
+ KEY `chains_group_owner` (`group_owner`),
17
+ CONSTRAINT `chains_group_owner` FOREIGN KEY (`group_owner`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
18
+ CONSTRAINT `chains_user_owner` FOREIGN KEY (`user_owner`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
20
+ end
21
+
22
+ down do
23
+ drop_table :chains
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `environments` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) NOT NULL DEFAULT '',
6
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
7
+ `user_owner` int(11) unsigned DEFAULT NULL,
8
+ `group_owner` int(11) unsigned DEFAULT NULL,
9
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
10
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
11
+ PRIMARY KEY (`id`),
12
+ UNIQUE KEY `name` (`name`),
13
+ KEY `active` (`active`),
14
+ KEY `environments_user_owner` (`user_owner`),
15
+ KEY `environments_group_owner` (`group_owner`),
16
+ CONSTRAINT `environments_group_owner` FOREIGN KEY (`group_owner`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
17
+ CONSTRAINT `environments_user_owner` FOREIGN KEY (`user_owner`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
18
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
19
+ end
20
+
21
+ down do
22
+ drop_table :environments
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `datacenters` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) NOT NULL DEFAULT '',
6
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
7
+ `user_owner` int(11) unsigned DEFAULT NULL,
8
+ `group_owner` int(11) unsigned DEFAULT NULL,
9
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
10
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
11
+ PRIMARY KEY (`id`),
12
+ UNIQUE KEY `name` (`name`),
13
+ KEY `active` (`active`),
14
+ KEY `datacenters_user_owner` (`user_owner`),
15
+ KEY `datacenters_group_owner` (`group_owner`),
16
+ CONSTRAINT `datacenters_group_owner` FOREIGN KEY (`group_owner`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
17
+ CONSTRAINT `datacenters_user_owner` FOREIGN KEY (`user_owner`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
18
+ ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;"
19
+ end
20
+
21
+ down do
22
+ drop_table :datacenters
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `nodes` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) NOT NULL DEFAULT '',
6
+ `datacenter_id` int(11) unsigned DEFAULT NULL,
7
+ `environment_id` int(11) unsigned DEFAULT NULL,
8
+ `status` varchar(255) NOT NULL DEFAULT 'unknown',
9
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
10
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
11
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
12
+ PRIMARY KEY (`id`),
13
+ UNIQUE KEY `name` (`name`),
14
+ KEY `active` (`active`),
15
+ KEY `status` (`status`),
16
+ KEY `node_datacenter_id` (`datacenter_id`),
17
+ KEY `node_environment_id` (`environment_id`),
18
+ CONSTRAINT `node_datacenter_id` FOREIGN KEY (`datacenter_id`) REFERENCES `datacenters` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
19
+ CONSTRAINT `node_environment_id` FOREIGN KEY (`environment_id`) REFERENCES `environments` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
20
+ ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;"
21
+ end
22
+
23
+ down do
24
+ drop_table :nodes
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `settings` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `key` varchar(128) NOT NULL,
6
+ `value` varchar(256) NOT NULL,
7
+ `encrypted` tinyint(1) unsigned NOT NULL DEFAULT '0',
8
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
9
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
10
+ PRIMARY KEY (`id`),
11
+ UNIQUE KEY `key` (`key`)
12
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
13
+ end
14
+
15
+ down do
16
+ drop_table :settings
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `extensions` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
6
+ `name` varchar(128) NOT NULL,
7
+ `namespace` varchar(128) NOT NULL DEFAULT '',
8
+ `exchange` varchar(255) DEFAULT NULL,
9
+ `uri` varchar(256) DEFAULT NULL,
10
+ `user_owner` int(11) unsigned DEFAULT NULL,
11
+ `group_owner` int(11) unsigned DEFAULT NULL,
12
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
13
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
14
+ PRIMARY KEY (`id`),
15
+ UNIQUE KEY `name_namespace` (`name`,`namespace`),
16
+ KEY `active` (`active`),
17
+ KEY `name` (`name`),
18
+ KEY `namespace` (`namespace`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
20
+ end
21
+
22
+ down do
23
+ drop_table :extensions
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `runners` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `extension_id` int(11) unsigned NOT NULL,
6
+ `name` varchar(256) NOT NULL DEFAULT '',
7
+ `namespace` varchar(256) NOT NULL DEFAULT '',
8
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
9
+ `queue` varchar(256) DEFAULT NULL,
10
+ `uri` varchar(256) DEFAULT NULL,
11
+ `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
12
+ `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
13
+ PRIMARY KEY (`id`),
14
+ CONSTRAINT `runner_extension_id` FOREIGN KEY (`extension_id`) REFERENCES `extensions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
16
+ end
17
+
18
+ down do
19
+ drop_table :runners
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `functions` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(128) NOT NULL,
6
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
7
+ `runner_id` int(11) unsigned NOT NULL,
8
+ `args` text,
9
+ `user_owner` int(11) unsigned DEFAULT NULL,
10
+ `group_owner` int(11) unsigned DEFAULT NULL,
11
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
12
+ `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
13
+ PRIMARY KEY (`id`),
14
+ UNIQUE KEY `runner_id` (`runner_id`,`name`),
15
+ KEY `active` (`active`),
16
+ KEY `namespace` (`runner_id`),
17
+ KEY `name` (`name`),
18
+ KEY `functions_user_owner` (`user_owner`),
19
+ KEY `functions_group_owner` (`group_owner`),
20
+ CONSTRAINT `function_runner_id` FOREIGN KEY (`runner_id`) REFERENCES `runners` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
21
+ CONSTRAINT `functions_group_owner` FOREIGN KEY (`group_owner`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
22
+ CONSTRAINT `functions_user_owner` FOREIGN KEY (`user_owner`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
24
+ end
25
+
26
+ down do
27
+ drop_table :functions
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `tasks` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `relationship_id` int(11) unsigned DEFAULT NULL,
6
+ `function_id` int(11) unsigned DEFAULT NULL,
7
+ `status` varchar(255) NOT NULL,
8
+ `parent_id` int(11) unsigned DEFAULT NULL,
9
+ `master_id` int(11) unsigned DEFAULT NULL,
10
+ `args` text,
11
+ `results` text,
12
+ `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
13
+ `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
14
+ PRIMARY KEY (`id`),
15
+ KEY `status` (`status`),
16
+ KEY `parent_id` (`parent_id`),
17
+ KEY `master_id` (`master_id`),
18
+ KEY `relationship_id` (`relationship_id`),
19
+ KEY `function_id` (`function_id`),
20
+ CONSTRAINT `parent_id` FOREIGN KEY (`parent_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
21
+ CONSTRAINT `master_id` FOREIGN KEY (`master_id`) REFERENCES `tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
22
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
23
+ end
24
+
25
+ down do
26
+ drop_table :tasks
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `task_logs` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `task_id` int(11) unsigned NOT NULL,
6
+ `function_id` int(11) unsigned,
7
+ `node_id` int(11) unsigned,
8
+ `entry` text NOT NULL,
9
+ `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
10
+ `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
11
+ PRIMARY KEY (`id`),
12
+ KEY (`created`),
13
+ KEY (`updated`),
14
+ CONSTRAINT `task_log_task_id` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
15
+ CONSTRAINT `task_log_functions` FOREIGN KEY (`function_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
16
+ CONSTRAINT `task_log_nodes` FOREIGN KEY (`node_id`) REFERENCES `nodes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
18
+ end
19
+
20
+ down do
21
+ drop_table :task_logs
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ Sequel.migration do
2
+ up do
3
+ run "CREATE TABLE `relationships` (
4
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
5
+ `name` varchar(255) DEFAULT NULL,
6
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
7
+ `chain_id` int(11) unsigned DEFAULT NULL,
8
+ `trigger_id` int(11) unsigned NOT NULL,
9
+ `action_id` int(11) unsigned NOT NULL,
10
+ `delay` int(11) unsigned NOT NULL DEFAULT '0',
11
+ `allow_new_chains` tinyint(1) unsigned NOT NULL DEFAULT '1',
12
+ `conditions` text,
13
+ `transformation` text,
14
+ `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
15
+ `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
16
+ PRIMARY KEY (`id`),
17
+ KEY `chain_id` (`chain_id`),
18
+ CONSTRAINT `function_chain_id` FOREIGN KEY (`chain_id`) REFERENCES `chains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
19
+ CONSTRAINT `relationship_action_id` FOREIGN KEY (`action_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
20
+ CONSTRAINT `relationship_trigger_id` FOREIGN KEY (`trigger_id`) REFERENCES `functions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
21
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
22
+ end
23
+
24
+ down do
25
+ drop_table :relationships
26
+ end
27
+ end