legion-data 0.1.0 → 1.1.4

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 -71
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +10 -7
  5. data/CHANGELOG.md +16 -0
  6. data/Gemfile +0 -3
  7. data/Gemfile.lock +100 -0
  8. data/README.md +13 -11
  9. data/legion-data.gemspec +22 -10
  10. data/lib/legion/data.rb +51 -33
  11. data/lib/legion/data/connection.rb +55 -19
  12. data/lib/legion/data/migration.rb +7 -20
  13. data/lib/legion/data/migrations/001_add_schema_columns.rb +1 -1
  14. data/lib/legion/data/migrations/002_add_users.rb +17 -0
  15. data/lib/legion/data/migrations/003_add_groups.rb +16 -0
  16. data/lib/legion/data/migrations/004_add_chains.rb +25 -0
  17. data/lib/legion/data/migrations/005_add_envs.rb +24 -0
  18. data/lib/legion/data/migrations/006_add_dcs.rb +24 -0
  19. data/lib/legion/data/migrations/007_add_nodes.rb +26 -0
  20. data/lib/legion/data/migrations/008_add_settings.rb +18 -0
  21. data/lib/legion/data/migrations/009_add_extensions.rb +25 -0
  22. data/lib/legion/data/migrations/010_add_runners.rb +21 -0
  23. data/lib/legion/data/migrations/011_add_functions.rb +29 -0
  24. data/lib/legion/data/migrations/012_add_tasks.rb +28 -0
  25. data/lib/legion/data/migrations/013_add_task_logs.rb +23 -0
  26. data/lib/legion/data/migrations/014_add_relationships.rb +27 -0
  27. data/lib/legion/data/migrations/015_add_default_extensions.rb +24 -0
  28. data/lib/legion/data/migrations/016_change_task_args.rb +7 -0
  29. data/lib/legion/data/migrations/017_add_payload_task.rb +7 -0
  30. data/lib/legion/data/migrations/018_add_migration_column.rb +7 -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 +119 -54
  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
@@ -10,24 +10,36 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Used by Legion to connect to the database'
12
12
  spec.description = 'The Legion connect gem'
13
- spec.homepage = 'https://bitbucket.org/legion-io/legion-data'
13
+ spec.homepage = 'https://bitbucket.org/legion-io/legion-data'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
15
 
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/legion-data/issues?status=new&status=open'
17
+ spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/legion-data/src/CHANGELOG.md'
18
+ spec.metadata['documentation_uri'] = 'https://bitbucket.org/legion-io/legion-data'
19
+ spec.metadata['homepage_uri'] = 'https://bitbucket.org/legion-io/legion-data'
20
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/legion-data'
21
+ spec.metadata['wiki_uri'] = 'https://bitbucket.org/legion-io/legion-data/wiki/Home'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
24
  f.match(%r{^(test|spec|features)/})
17
25
  end
18
- spec.bindir = 'exe'
26
+ spec.bindir = 'bin'
19
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
28
  spec.require_paths = ['lib']
21
29
 
22
30
  spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'codecov', '~> 0'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'rspec', '~> 3.0'
26
- spec.add_development_dependency 'rspec_junit_formatter', '~> 0'
27
- spec.add_development_dependency 'rubocop', '~> 0'
31
+ spec.add_development_dependency 'codecov'
32
+ spec.add_development_dependency 'rake'
33
+ spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'rspec_junit_formatter'
35
+ spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop-md'
37
+ spec.add_development_dependency 'rubocop-performance'
38
+ spec.add_development_dependency 'rubocop-rspec'
39
+ spec.add_development_dependency 'rubocop-sequel'
28
40
 
29
- spec.add_dependency 'legion-logging', '~>0.1'
30
- spec.add_dependency 'legion-settings', '~>0.1'
41
+ spec.add_dependency 'legion-logging'
42
+ spec.add_dependency 'legion-settings'
31
43
 
32
44
  if RUBY_ENGINE == 'jruby'
33
45
  spec.add_dependency 'jdbc-mysql'
@@ -1,43 +1,61 @@
1
1
  require 'legion/data/version'
2
+ require 'legion/data/settings'
2
3
  require 'sequel'
4
+
3
5
  require 'legion/data/connection'
4
- require 'legion/data/migration'
5
6
  require 'legion/data/model'
7
+ require 'legion/data/migration'
6
8
 
7
9
  module Legion
8
10
  module Data
9
- def build(options = {})
10
- @connected = false
11
- options.merge!(default_options) { |_key, v1, _v2| v1 }
12
- @connection = connect(options[:connection]) if options[:connection][:auto_connect]
13
- return unless options[:connection][:auto_connect]
14
-
15
- migrate(@connection, options[:migration])
16
- model(options[:model]) if options[:model][:auto_load]
17
- end
18
-
19
- def connect(_options = {})
20
- Legion::Data::Connection.new
21
- end
22
-
23
- def migrate(connection, options = {})
24
- return false if options.key?(:auto_migrate) && options[:auto_migrate]
25
-
26
- Legion::Data::Migration.new(connection.database.connection)
27
- end
28
-
29
- def model(_options = {})
30
- Legion::Data::Models.new
31
- end
32
-
33
- def default_options
34
- { migration: { auto_migrate: true },
35
- model: { auto_load: true },
36
- connection: { auto_connect: true } }
37
- end
38
-
39
- def merge_options(options, default = default_options)
40
- options.merge!(default) { |_key, v1, _v2| v1 }
11
+ class << self
12
+ def setup
13
+ connection_setup
14
+ migrate
15
+ load_models
16
+ setup_cache
17
+ end
18
+
19
+ def connection_setup
20
+ return if Legion::Settings[:data][:connected]
21
+
22
+ Legion::Data::Connection.setup
23
+ end
24
+
25
+ def migrate
26
+ Legion::Data::Migration.migrate
27
+ end
28
+
29
+ def load_models
30
+ Legion::Data::Models.load
31
+ end
32
+
33
+ def connection
34
+ Legion::Data::Connection.sequel
35
+ end
36
+
37
+ def setup_cache
38
+ return if Legion::Settings[:data][:cache][:enabled]
39
+
40
+ return unless defined?(::Legion::Cache)
41
+
42
+ Legion::Data::Model::Relationship.plugin :caching, Legion::Cache, ttl: 10
43
+ Legion::Data::Model::Runner.plugin :caching, Legion::Cache, ttl: 60
44
+ Legion::Data::Model::Chain.plugin :caching, Legion::Cache, ttl: 60
45
+ Legion::Data::Model::Datacenter.plugin :caching, Legion::Cache, ttl: 120
46
+ Legion::Data::Model::Function.plugin :caching, Legion::Cache, ttl: 120
47
+ Legion::Data::Model::Extension.plugin :caching, Legion::Cache, ttl: 120
48
+ Legion::Data::Model::Node.plugin :caching, Legion::Cache, ttl: 10
49
+ Legion::Data::Model::TaskLog.plugin :caching, Legion::Cache, ttl: 12
50
+ Legion::Data::Model::Task.plugin :caching, Legion::Cache, ttl: 10
51
+ Legion::Data::Model::User.plugin :caching, Legion::Cache, ttl: 120
52
+ Legion::Data::Model::Group.plugin :caching, Legion::Cache, ttl: 120
53
+ Legion::Logging.info 'Legion::Data connected to Legion::Cache'
54
+ end
55
+
56
+ def shutdown
57
+ Legion::Data::Connection.shutdown
58
+ end
41
59
  end
42
60
  end
43
61
  end
@@ -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 => ex
20
- Legion::Logging.error(ex.message)
21
- raise ex
22
- rescue StandardError => ex
23
- Legion::Logging.error(ex.message)
24
- raise ex 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