convergence 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +55 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +52 -0
- data/CONTRIBUTING.md +80 -0
- data/Gemfile.lock +24 -9
- data/README.md +131 -1
- data/Rakefile +48 -5
- data/convergence.gemspec +3 -1
- data/lib/convergence/cli.rb +10 -2
- data/lib/convergence/command/apply.rb +38 -9
- data/lib/convergence/command/dryrun.rb +5 -5
- data/lib/convergence/command/export.rb +19 -1
- data/lib/convergence/command.rb +6 -0
- data/lib/convergence/config.rb +1 -1
- data/lib/convergence/database_connector/postgres_connector.rb +25 -0
- data/lib/convergence/database_connector/sqlite_connector.rb +22 -0
- data/lib/convergence/database_connector.rb +6 -0
- data/lib/convergence/default_parameter/mysql_default_parameter.rb +1 -1
- data/lib/convergence/default_parameter/postgres_default_parameter.rb +57 -0
- data/lib/convergence/default_parameter/sqlite_default_parameter.rb +57 -0
- data/lib/convergence/default_parameter.rb +6 -0
- data/lib/convergence/diff.rb +9 -2
- data/lib/convergence/dsl.rb +18 -3
- data/lib/convergence/dumper/mysql_schema_dumper.rb +37 -9
- data/lib/convergence/dumper/postgres_schema_dumper.rb +193 -0
- data/lib/convergence/dumper/sqlite_schema_dumper.rb +132 -0
- data/lib/convergence/dumper.rb +113 -0
- data/lib/convergence/sql_generator/mysql_generator.rb +18 -3
- data/lib/convergence/sql_generator/postgres_generator.rb +256 -0
- data/lib/convergence/sql_generator/sqlite_generator.rb +178 -0
- data/lib/convergence/version.rb +1 -1
- data/spec/config/spec_database.yml +15 -2
- data/spec/convergence/config_spec.rb +75 -0
- data/spec/convergence/diff_spec.rb +125 -45
- data/spec/convergence/dsl_spec.rb +26 -0
- data/spec/convergence/dumper/mysql_schema_dumper_spec.rb +25 -2
- data/spec/convergence/dumper/postgres_schema_dumper_spec.rb +103 -0
- data/spec/convergence/dumper/sqlite_schema_dumper_spec.rb +85 -0
- data/spec/convergence/dumper_spec.rb +110 -16
- data/spec/convergence/foreign_key_spec.rb +33 -0
- data/spec/convergence/index_spec.rb +52 -0
- data/spec/convergence/pretty_diff_spec.rb +85 -0
- data/spec/convergence/table_spec.rb +23 -0
- data/spec/fixtures/add_table_with_enum_set.schema +5 -0
- data/spec/fixtures/change_table_comment_to_paper.schema +2 -0
- data/spec/fixtures/execute_raw_sql.schema +28 -0
- data/spec/fixtures/postgres/add_columns_to_paper.schema +29 -0
- data/spec/fixtures/postgres/add_table.schema +32 -0
- data/spec/fixtures/postgres/change_comment_columns_to_paper.schema +28 -0
- data/spec/fixtures/postgres/change_table_comment_to_paper.schema +28 -0
- data/spec/fixtures/postgres/drop_foreign_key.schema +25 -0
- data/spec/fixtures/postgres/drop_table.schema +19 -0
- data/spec/fixtures/postgres/remove_columns_to_paper.schema +27 -0
- data/spec/fixtures/postgres_test_db.sql +41 -0
- data/spec/fixtures/sqlite/add_columns_to_paper.schema +29 -0
- data/spec/fixtures/sqlite/add_table.schema +32 -0
- data/spec/fixtures/sqlite/change_columns_to_paper.schema +28 -0
- data/spec/fixtures/sqlite/drop_foreign_key.schema +25 -0
- data/spec/fixtures/sqlite/drop_table.schema +19 -0
- data/spec/fixtures/sqlite/remove_columns_to_paper.schema +27 -0
- data/spec/fixtures/sqlite_test_db.sql +31 -0
- data/spec/fixtures/test_db.sql +10 -0
- data/spec/integrations/command_diff.rb +35 -0
- data/spec/integrations/command_dryrun.rb +37 -2
- data/spec/integrations/command_export.rb +28 -0
- data/spec/postgres_integrations/command_dryrun.rb +79 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/sqlite_integrations/command_dryrun.rb +70 -0
- metadata +97 -9
- data/.travis.yml +0 -9
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
DROP TABLE IF EXISTS paper_authors;
|
|
2
|
+
DROP TABLE IF EXISTS papers;
|
|
3
|
+
DROP TABLE IF EXISTS authors;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE authors (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
name varchar(110) NOT NULL,
|
|
8
|
+
age int NOT NULL,
|
|
9
|
+
created_at datetime,
|
|
10
|
+
updated_at datetime
|
|
11
|
+
);
|
|
12
|
+
CREATE INDEX index_authors_on_created_at ON authors (created_at);
|
|
13
|
+
|
|
14
|
+
CREATE TABLE papers (
|
|
15
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
16
|
+
slug varchar(255) NOT NULL,
|
|
17
|
+
title1 varchar(300) NOT NULL,
|
|
18
|
+
title2 varchar(300) NOT NULL,
|
|
19
|
+
description text,
|
|
20
|
+
edition_number int NOT NULL DEFAULT 0,
|
|
21
|
+
published_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
22
|
+
);
|
|
23
|
+
CREATE UNIQUE INDEX index_papers_on_slug ON papers (slug);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE paper_authors (
|
|
26
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
27
|
+
paper_id int NOT NULL,
|
|
28
|
+
author_id int NOT NULL,
|
|
29
|
+
CONSTRAINT paper_authors_author_id_fk FOREIGN KEY (author_id) REFERENCES authors (id),
|
|
30
|
+
CONSTRAINT paper_authors_paper_id_fk FOREIGN KEY (paper_id) REFERENCES papers (id)
|
|
31
|
+
);
|
data/spec/fixtures/test_db.sql
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
DROP TABLE IF EXISTS `paper_authors`;
|
|
2
2
|
DROP TABLE IF EXISTS `papers`;
|
|
3
3
|
DROP TABLE IF EXISTS `authors`;
|
|
4
|
+
DROP TABLE IF EXISTS `enum_set_samples`;
|
|
4
5
|
|
|
5
6
|
CREATE TABLE `papers` (
|
|
6
7
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
@@ -8,6 +9,8 @@ CREATE TABLE `papers` (
|
|
|
8
9
|
`title1` varchar(300) NOT NULL COMMENT 'Title 1',
|
|
9
10
|
`title2` varchar(300) NOT NULL COMMENT 'Title 2',
|
|
10
11
|
`description` text COMMENT 'Description',
|
|
12
|
+
`edition_number` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Edition number',
|
|
13
|
+
`published_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Published at',
|
|
11
14
|
PRIMARY KEY (`id`),
|
|
12
15
|
UNIQUE KEY `index_papers_on_slug` (`slug`),
|
|
13
16
|
KEY `index_papers_on_title1_title2` (`title1` (100), `title2` (200))
|
|
@@ -33,3 +36,10 @@ CREATE TABLE `paper_authors` (
|
|
|
33
36
|
CONSTRAINT `paper_authors_author_id_fk` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`),
|
|
34
37
|
CONSTRAINT `paper_authors_paper_id_fk` FOREIGN KEY (`paper_id`) REFERENCES `papers` (`id`)
|
|
35
38
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='Paper Author Relation';
|
|
39
|
+
|
|
40
|
+
CREATE TABLE `enum_set_samples` (
|
|
41
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
42
|
+
`status` enum('active','inactive','pending') NOT NULL DEFAULT 'active',
|
|
43
|
+
`flags` set('a','b','it''s tricky') NOT NULL,
|
|
44
|
+
PRIMARY KEY (`id`)
|
|
45
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'convergence/command/diff'
|
|
3
|
+
|
|
4
|
+
describe 'Command::Diff#execute' do
|
|
5
|
+
def execute(file1, file2)
|
|
6
|
+
opts = {
|
|
7
|
+
diff: [
|
|
8
|
+
File.expand_path("#{File.dirname(__FILE__)}/../fixtures/#{file1}"),
|
|
9
|
+
File.expand_path("#{File.dirname(__FILE__)}/../fixtures/#{file2}")
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
Convergence::Command::Diff.new(opts, config: nil).execute
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should show tables only present in the second file as added' do
|
|
16
|
+
result = execute('drop_table.schema', 'add_table.schema')
|
|
17
|
+
expect(result).to be_include('+ create_table :paper_authors, collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should show tables only present in the first file as removed' do
|
|
21
|
+
result = execute('add_table.schema', 'drop_table.schema')
|
|
22
|
+
expect(result).to be_include('- create_table :paper_authors, collate: "utf8_general_ci", comment: "Paper Author Relation" do |t|')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should show a column change between the two files as a unified diff' do
|
|
26
|
+
result = execute('add_table.schema', 'change_comment_columns_to_paper.schema')
|
|
27
|
+
expect(result).to be_include("- t.datetime :created_at, null: true\n")
|
|
28
|
+
expect(result).to be_include("+ t.datetime :created_at, null: true, comment: \"Created At\"\n")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should be empty when comparing a schema file with itself' do
|
|
32
|
+
result = execute('add_table.schema', 'add_table.schema')
|
|
33
|
+
expect(result).to eq('')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
|
2
2
|
require 'convergence/command/dryrun'
|
|
3
3
|
|
|
4
4
|
describe 'Command::Dryrun#execute' do
|
|
5
|
-
def execute(dsl_path)
|
|
5
|
+
def execute(dsl_path, extra_options = {})
|
|
6
6
|
parse_option = {
|
|
7
7
|
input: File.expand_path("#{File.dirname(__FILE__)}/../fixtures/#{dsl_path}")
|
|
8
|
-
}
|
|
8
|
+
}.merge(extra_options)
|
|
9
9
|
Convergence::Command::Dryrun.new(parse_option, config: mysql_settings).execute
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -35,6 +35,25 @@ describe 'Command::Dryrun#execute' do
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
describe 'add table with enum/set columns' do
|
|
39
|
+
let(:exec_dsl) { 'add_table_with_enum_set.schema' }
|
|
40
|
+
let(:expect_query) do
|
|
41
|
+
q = <<-QUERY
|
|
42
|
+
# CREATE TABLE `enum_set_dummies` (
|
|
43
|
+
# `id` int(11) NOT NULL AUTO_INCREMENT,
|
|
44
|
+
# `status` enum('active','inactive','pending') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'active',
|
|
45
|
+
# `flags` set('a','b','c') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
|
46
|
+
# PRIMARY KEY (`id`)
|
|
47
|
+
# ) ENGINE=InnoDB ROW_FORMAT=Compact DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
|
|
48
|
+
QUERY
|
|
49
|
+
q.strip
|
|
50
|
+
end
|
|
51
|
+
it 'should be output create table query with quoted enum/set values' do
|
|
52
|
+
result = execute(exec_dsl)
|
|
53
|
+
expect(result).to be_include(expect_query)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
38
57
|
describe 'drop table' do
|
|
39
58
|
let(:exec_dsl) { 'drop_table.schema' }
|
|
40
59
|
|
|
@@ -42,6 +61,22 @@ describe 'Command::Dryrun#execute' do
|
|
|
42
61
|
result = execute(exec_dsl)
|
|
43
62
|
expect(result).to be_include('DROP TABLE `paper_authors`')
|
|
44
63
|
end
|
|
64
|
+
|
|
65
|
+
context 'when safe_migration is enabled' do
|
|
66
|
+
it 'should not output drop table query' do
|
|
67
|
+
result = execute(exec_dsl, safe_migration: true)
|
|
68
|
+
expect(result).not_to be_include('DROP TABLE `paper_authors`')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe 'execute raw sql' do
|
|
74
|
+
let(:exec_dsl) { 'execute_raw_sql.schema' }
|
|
75
|
+
|
|
76
|
+
it 'should be output the raw sql statement after the generated schema changes' do
|
|
77
|
+
result = execute(exec_dsl)
|
|
78
|
+
expect(result).to be_include('# UPDATE authors SET age = 0 WHERE age IS NULL;')
|
|
79
|
+
end
|
|
45
80
|
end
|
|
46
81
|
|
|
47
82
|
describe 'add columns' do
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'convergence/command/export'
|
|
3
|
+
|
|
4
|
+
describe 'Command::Export#execute' do
|
|
5
|
+
def execute(extra_options = {})
|
|
6
|
+
Convergence::Command::Export.new(extra_options, config: mysql_settings).execute
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'should be output convergence DSL by default' do
|
|
10
|
+
result = execute
|
|
11
|
+
expect(result).to be_include('create_table :authors')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '--dump-rails-migration' do
|
|
15
|
+
it 'should be output an ActiveRecord migration' do
|
|
16
|
+
result = execute(dump_rails_migration: true, filename: 'add_initial_tables')
|
|
17
|
+
expect(result).to be_include('# Filename:')
|
|
18
|
+
expect(result).to be_include('_add_initial_tables.rb')
|
|
19
|
+
expect(result).to be_include('class AddInitialTables < ActiveRecord::Migration[')
|
|
20
|
+
expect(result).to be_include('create_table :authors do |t|')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should use a default filename/class name when --filename is omitted' do
|
|
24
|
+
result = execute(dump_rails_migration: true)
|
|
25
|
+
expect(result).to be_include('class ConvergenceMigration < ActiveRecord::Migration[')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'convergence/command/dryrun'
|
|
3
|
+
|
|
4
|
+
describe 'PostgreSQL Command::Dryrun#execute' do
|
|
5
|
+
def execute(dsl_path, extra_options = {})
|
|
6
|
+
parse_option = {
|
|
7
|
+
input: File.expand_path("#{File.dirname(__FILE__)}/../fixtures/postgres/#{dsl_path}")
|
|
8
|
+
}.merge(extra_options)
|
|
9
|
+
Convergence::Command::Dryrun.new(parse_option, config: postgres_settings).execute
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'change table options' do
|
|
13
|
+
let(:exec_dsl) { 'change_table_comment_to_paper.schema' }
|
|
14
|
+
|
|
15
|
+
it 'should be output alter table query' do
|
|
16
|
+
result = execute(exec_dsl)
|
|
17
|
+
expect(result).to be_include(%(# COMMENT ON TABLE "authors" IS 'Author Table';))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'add table' do
|
|
22
|
+
let(:exec_dsl) { 'add_table.schema' }
|
|
23
|
+
|
|
24
|
+
it 'should be output create table query' do
|
|
25
|
+
result = execute(exec_dsl)
|
|
26
|
+
expect(result).to be_include(%(# "id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,))
|
|
27
|
+
expect(result).to be_include(%(# COMMENT ON TABLE "dummies" IS 'Dummy Table';))
|
|
28
|
+
expect(result).to be_include(%(# COMMENT ON COLUMN "dummies"."id" IS 'Hello Convergence';))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe 'drop table' do
|
|
33
|
+
let(:exec_dsl) { 'drop_table.schema' }
|
|
34
|
+
|
|
35
|
+
it 'should be output drop table query' do
|
|
36
|
+
result = execute(exec_dsl)
|
|
37
|
+
expect(result).to be_include('DROP TABLE "paper_authors";')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'add columns' do
|
|
42
|
+
let(:exec_dsl) { 'add_columns_to_paper.schema' }
|
|
43
|
+
|
|
44
|
+
it 'should be output alter add column query' do
|
|
45
|
+
result = execute(exec_dsl)
|
|
46
|
+
expect(result).to be_include(%(# ALTER TABLE "papers" ADD COLUMN "subtitle" varchar DEFAULT NULL;))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe 'remove columns' do
|
|
51
|
+
let(:exec_dsl) { 'remove_columns_to_paper.schema' }
|
|
52
|
+
|
|
53
|
+
it 'should be output alter drop column query' do
|
|
54
|
+
result = execute(exec_dsl)
|
|
55
|
+
expect(result).to be_include(%(# ALTER TABLE "papers" DROP COLUMN "description";))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'change columns' do
|
|
60
|
+
describe 'change comment' do
|
|
61
|
+
let(:exec_dsl) { 'change_comment_columns_to_paper.schema' }
|
|
62
|
+
|
|
63
|
+
it 'should be output alter table column query' do
|
|
64
|
+
result = execute(exec_dsl)
|
|
65
|
+
expect(result).to be_include(%(# COMMENT ON COLUMN "authors"."created_at" IS 'Created At';))
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe 'drop foreign key' do
|
|
71
|
+
let(:exec_dsl) { 'drop_foreign_key.schema' }
|
|
72
|
+
|
|
73
|
+
it 'should be output drop foreign key query' do
|
|
74
|
+
result = execute(exec_dsl)
|
|
75
|
+
expect(result).to be_include(%(# ALTER TABLE "paper_authors" DROP CONSTRAINT "paper_authors_author_id_fk";))
|
|
76
|
+
expect(result).to be_include(%(# ALTER TABLE "paper_authors" DROP CONSTRAINT "paper_authors_paper_id_fk";))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -5,6 +5,8 @@ require 'pry'
|
|
|
5
5
|
require 'convergence'
|
|
6
6
|
require 'convergence/database_connector'
|
|
7
7
|
Dir["#{File.dirname(__FILE__)}/integrations/**/*.rb"].each { |f| require f }
|
|
8
|
+
Dir["#{File.dirname(__FILE__)}/postgres_integrations/**/*.rb"].each { |f| require f }
|
|
9
|
+
Dir["#{File.dirname(__FILE__)}/sqlite_integrations/**/*.rb"].each { |f| require f }
|
|
8
10
|
|
|
9
11
|
$default_output = File.open('/dev/null', 'w')
|
|
10
12
|
|
|
@@ -13,6 +15,17 @@ def mysql_settings
|
|
|
13
15
|
Convergence::Config.new(Hash[mysql_settings.map { |k, v| [k.to_sym, v] }])
|
|
14
16
|
end
|
|
15
17
|
|
|
18
|
+
def postgres_settings
|
|
19
|
+
postgres_settings = YAML.load_file("#{File.dirname(__FILE__)}/config/spec_database.yml")['postgresql']
|
|
20
|
+
Convergence::Config.new(Hash[postgres_settings.map { |k, v| [k.to_sym, v] }])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def sqlite_settings
|
|
24
|
+
sqlite_settings = YAML.load_file("#{File.dirname(__FILE__)}/config/spec_database.yml")['sqlite3']
|
|
25
|
+
database_path = File.expand_path("#{File.dirname(__FILE__)}/fixtures/#{sqlite_settings['database']}")
|
|
26
|
+
Convergence::Config.new(adapter: sqlite_settings['adapter'], database: database_path)
|
|
27
|
+
end
|
|
28
|
+
|
|
16
29
|
def rollback
|
|
17
30
|
# FIXME But I have no idea to rollback create/drop/alter table of mysql
|
|
18
31
|
sqls = File.open("#{File.dirname(__FILE__)}/fixtures/test_db.sql")
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'convergence/command/dryrun'
|
|
3
|
+
|
|
4
|
+
describe 'SQLite Command::Dryrun#execute' do
|
|
5
|
+
def execute(dsl_path, extra_options = {})
|
|
6
|
+
parse_option = {
|
|
7
|
+
input: File.expand_path("#{File.dirname(__FILE__)}/../fixtures/sqlite/#{dsl_path}")
|
|
8
|
+
}.merge(extra_options)
|
|
9
|
+
Convergence::Command::Dryrun.new(parse_option, config: sqlite_settings).execute
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'add table' do
|
|
13
|
+
let(:exec_dsl) { 'add_table.schema' }
|
|
14
|
+
|
|
15
|
+
it 'should be output create table query' do
|
|
16
|
+
result = execute(exec_dsl)
|
|
17
|
+
expect(result).to be_include(%(# CREATE TABLE "dummies" (\n# "id" INTEGER PRIMARY KEY AUTOINCREMENT\n# );))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'drop table' do
|
|
22
|
+
let(:exec_dsl) { 'drop_table.schema' }
|
|
23
|
+
|
|
24
|
+
it 'should be output drop table query' do
|
|
25
|
+
result = execute(exec_dsl)
|
|
26
|
+
expect(result).to be_include('DROP TABLE "paper_authors";')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'when safe_migration is enabled' do
|
|
30
|
+
it 'should not output drop table query' do
|
|
31
|
+
result = execute(exec_dsl, safe_migration: true)
|
|
32
|
+
expect(result).not_to be_include('DROP TABLE "paper_authors";')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe 'add columns' do
|
|
38
|
+
let(:exec_dsl) { 'add_columns_to_paper.schema' }
|
|
39
|
+
|
|
40
|
+
it 'should be output alter add column query' do
|
|
41
|
+
result = execute(exec_dsl)
|
|
42
|
+
expect(result).to be_include(%(# ALTER TABLE "papers" ADD COLUMN "subtitle" varchar;))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe 'remove columns' do
|
|
47
|
+
let(:exec_dsl) { 'remove_columns_to_paper.schema' }
|
|
48
|
+
|
|
49
|
+
it 'should be output alter drop column query' do
|
|
50
|
+
result = execute(exec_dsl)
|
|
51
|
+
expect(result).to be_include(%(# ALTER TABLE "papers" DROP COLUMN "description";))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'change columns' do
|
|
56
|
+
let(:exec_dsl) { 'change_columns_to_paper.schema' }
|
|
57
|
+
|
|
58
|
+
it 'should raise NotImplementedError since SQLite cannot ALTER a column in place' do
|
|
59
|
+
expect { execute(exec_dsl) }.to raise_error(NotImplementedError, /does not support changing column/)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe 'drop foreign key' do
|
|
64
|
+
let(:exec_dsl) { 'drop_foreign_key.schema' }
|
|
65
|
+
|
|
66
|
+
it 'should raise NotImplementedError since SQLite cannot drop a foreign key in place' do
|
|
67
|
+
expect { execute(exec_dsl) }.to raise_error(NotImplementedError, /does not support removing a foreign key/)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: convergence
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shinsuke Nishio
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: mysql2
|
|
@@ -25,7 +24,7 @@ dependencies:
|
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
27
|
+
name: pg
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - ">="
|
|
@@ -39,7 +38,21 @@ dependencies:
|
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '0'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
41
|
+
name: sqlite3
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: diff-lcs
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
44
57
|
requirements:
|
|
45
58
|
- - ">="
|
|
@@ -52,6 +65,20 @@ dependencies:
|
|
|
52
65
|
- - ">="
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
67
|
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: diffy
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 3.4.2
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 3.4.2
|
|
55
82
|
- !ruby/object:Gem::Dependency
|
|
56
83
|
name: thor
|
|
57
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -158,11 +185,12 @@ executables:
|
|
|
158
185
|
extensions: []
|
|
159
186
|
extra_rdoc_files: []
|
|
160
187
|
files:
|
|
188
|
+
- ".github/workflows/ruby.yml"
|
|
161
189
|
- ".gitignore"
|
|
162
190
|
- ".rspec"
|
|
163
191
|
- ".rubocop.yml"
|
|
164
|
-
- ".travis.yml"
|
|
165
192
|
- CHANGELOG.md
|
|
193
|
+
- CONTRIBUTING.md
|
|
166
194
|
- Gemfile
|
|
167
195
|
- Gemfile.lock
|
|
168
196
|
- Guardfile
|
|
@@ -184,12 +212,18 @@ files:
|
|
|
184
212
|
- lib/convergence/config.rb
|
|
185
213
|
- lib/convergence/database_connector.rb
|
|
186
214
|
- lib/convergence/database_connector/mysql_connector.rb
|
|
215
|
+
- lib/convergence/database_connector/postgres_connector.rb
|
|
216
|
+
- lib/convergence/database_connector/sqlite_connector.rb
|
|
187
217
|
- lib/convergence/default_parameter.rb
|
|
188
218
|
- lib/convergence/default_parameter/mysql_default_parameter.rb
|
|
219
|
+
- lib/convergence/default_parameter/postgres_default_parameter.rb
|
|
220
|
+
- lib/convergence/default_parameter/sqlite_default_parameter.rb
|
|
189
221
|
- lib/convergence/diff.rb
|
|
190
222
|
- lib/convergence/dsl.rb
|
|
191
223
|
- lib/convergence/dumper.rb
|
|
192
224
|
- lib/convergence/dumper/mysql_schema_dumper.rb
|
|
225
|
+
- lib/convergence/dumper/postgres_schema_dumper.rb
|
|
226
|
+
- lib/convergence/dumper/sqlite_schema_dumper.rb
|
|
193
227
|
- lib/convergence/foreign_key.rb
|
|
194
228
|
- lib/convergence/index.rb
|
|
195
229
|
- lib/convergence/logger.rb
|
|
@@ -197,31 +231,59 @@ files:
|
|
|
197
231
|
- lib/convergence/pretty_diff.rb
|
|
198
232
|
- lib/convergence/sql_generator.rb
|
|
199
233
|
- lib/convergence/sql_generator/mysql_generator.rb
|
|
234
|
+
- lib/convergence/sql_generator/postgres_generator.rb
|
|
235
|
+
- lib/convergence/sql_generator/sqlite_generator.rb
|
|
200
236
|
- lib/convergence/table.rb
|
|
201
237
|
- lib/convergence/version.rb
|
|
202
238
|
- spec/config/spec_database.yml
|
|
239
|
+
- spec/convergence/config_spec.rb
|
|
203
240
|
- spec/convergence/diff_spec.rb
|
|
204
241
|
- spec/convergence/dsl_spec.rb
|
|
205
242
|
- spec/convergence/dumper/mysql_schema_dumper_spec.rb
|
|
243
|
+
- spec/convergence/dumper/postgres_schema_dumper_spec.rb
|
|
244
|
+
- spec/convergence/dumper/sqlite_schema_dumper_spec.rb
|
|
206
245
|
- spec/convergence/dumper_spec.rb
|
|
246
|
+
- spec/convergence/foreign_key_spec.rb
|
|
247
|
+
- spec/convergence/index_spec.rb
|
|
248
|
+
- spec/convergence/pretty_diff_spec.rb
|
|
207
249
|
- spec/convergence/table_spec.rb
|
|
208
250
|
- spec/fixtures/add_columns_to_paper.schema
|
|
209
251
|
- spec/fixtures/add_table.schema
|
|
252
|
+
- spec/fixtures/add_table_with_enum_set.schema
|
|
210
253
|
- spec/fixtures/change_comment_columns_to_paper.schema
|
|
211
254
|
- spec/fixtures/change_foreign_key.schema
|
|
212
255
|
- spec/fixtures/change_table_comment_to_paper.schema
|
|
213
256
|
- spec/fixtures/drop_foreign_key.schema
|
|
214
257
|
- spec/fixtures/drop_table.schema
|
|
258
|
+
- spec/fixtures/execute_raw_sql.schema
|
|
259
|
+
- spec/fixtures/postgres/add_columns_to_paper.schema
|
|
260
|
+
- spec/fixtures/postgres/add_table.schema
|
|
261
|
+
- spec/fixtures/postgres/change_comment_columns_to_paper.schema
|
|
262
|
+
- spec/fixtures/postgres/change_table_comment_to_paper.schema
|
|
263
|
+
- spec/fixtures/postgres/drop_foreign_key.schema
|
|
264
|
+
- spec/fixtures/postgres/drop_table.schema
|
|
265
|
+
- spec/fixtures/postgres/remove_columns_to_paper.schema
|
|
266
|
+
- spec/fixtures/postgres_test_db.sql
|
|
215
267
|
- spec/fixtures/remove_columns_to_paper.schema
|
|
268
|
+
- spec/fixtures/sqlite/add_columns_to_paper.schema
|
|
269
|
+
- spec/fixtures/sqlite/add_table.schema
|
|
270
|
+
- spec/fixtures/sqlite/change_columns_to_paper.schema
|
|
271
|
+
- spec/fixtures/sqlite/drop_foreign_key.schema
|
|
272
|
+
- spec/fixtures/sqlite/drop_table.schema
|
|
273
|
+
- spec/fixtures/sqlite/remove_columns_to_paper.schema
|
|
274
|
+
- spec/fixtures/sqlite_test_db.sql
|
|
216
275
|
- spec/fixtures/test_db.sql
|
|
276
|
+
- spec/integrations/command_diff.rb
|
|
217
277
|
- spec/integrations/command_dryrun.rb
|
|
278
|
+
- spec/integrations/command_export.rb
|
|
218
279
|
- spec/integrations/drop_foreign_key.rb
|
|
280
|
+
- spec/postgres_integrations/command_dryrun.rb
|
|
219
281
|
- spec/spec_helper.rb
|
|
282
|
+
- spec/sqlite_integrations/command_dryrun.rb
|
|
220
283
|
homepage: https://github.com/nishio-dens/convergence
|
|
221
284
|
licenses:
|
|
222
285
|
- MIT
|
|
223
286
|
metadata: {}
|
|
224
|
-
post_install_message:
|
|
225
287
|
rdoc_options: []
|
|
226
288
|
require_paths:
|
|
227
289
|
- lib
|
|
@@ -236,26 +298,52 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
236
298
|
- !ruby/object:Gem::Version
|
|
237
299
|
version: '0'
|
|
238
300
|
requirements: []
|
|
239
|
-
rubygems_version:
|
|
240
|
-
signing_key:
|
|
301
|
+
rubygems_version: 4.0.3
|
|
241
302
|
specification_version: 4
|
|
242
303
|
summary: DB Schema management tool
|
|
243
304
|
test_files:
|
|
244
305
|
- spec/config/spec_database.yml
|
|
306
|
+
- spec/convergence/config_spec.rb
|
|
245
307
|
- spec/convergence/diff_spec.rb
|
|
246
308
|
- spec/convergence/dsl_spec.rb
|
|
247
309
|
- spec/convergence/dumper/mysql_schema_dumper_spec.rb
|
|
310
|
+
- spec/convergence/dumper/postgres_schema_dumper_spec.rb
|
|
311
|
+
- spec/convergence/dumper/sqlite_schema_dumper_spec.rb
|
|
248
312
|
- spec/convergence/dumper_spec.rb
|
|
313
|
+
- spec/convergence/foreign_key_spec.rb
|
|
314
|
+
- spec/convergence/index_spec.rb
|
|
315
|
+
- spec/convergence/pretty_diff_spec.rb
|
|
249
316
|
- spec/convergence/table_spec.rb
|
|
250
317
|
- spec/fixtures/add_columns_to_paper.schema
|
|
251
318
|
- spec/fixtures/add_table.schema
|
|
319
|
+
- spec/fixtures/add_table_with_enum_set.schema
|
|
252
320
|
- spec/fixtures/change_comment_columns_to_paper.schema
|
|
253
321
|
- spec/fixtures/change_foreign_key.schema
|
|
254
322
|
- spec/fixtures/change_table_comment_to_paper.schema
|
|
255
323
|
- spec/fixtures/drop_foreign_key.schema
|
|
256
324
|
- spec/fixtures/drop_table.schema
|
|
325
|
+
- spec/fixtures/execute_raw_sql.schema
|
|
326
|
+
- spec/fixtures/postgres/add_columns_to_paper.schema
|
|
327
|
+
- spec/fixtures/postgres/add_table.schema
|
|
328
|
+
- spec/fixtures/postgres/change_comment_columns_to_paper.schema
|
|
329
|
+
- spec/fixtures/postgres/change_table_comment_to_paper.schema
|
|
330
|
+
- spec/fixtures/postgres/drop_foreign_key.schema
|
|
331
|
+
- spec/fixtures/postgres/drop_table.schema
|
|
332
|
+
- spec/fixtures/postgres/remove_columns_to_paper.schema
|
|
333
|
+
- spec/fixtures/postgres_test_db.sql
|
|
257
334
|
- spec/fixtures/remove_columns_to_paper.schema
|
|
335
|
+
- spec/fixtures/sqlite/add_columns_to_paper.schema
|
|
336
|
+
- spec/fixtures/sqlite/add_table.schema
|
|
337
|
+
- spec/fixtures/sqlite/change_columns_to_paper.schema
|
|
338
|
+
- spec/fixtures/sqlite/drop_foreign_key.schema
|
|
339
|
+
- spec/fixtures/sqlite/drop_table.schema
|
|
340
|
+
- spec/fixtures/sqlite/remove_columns_to_paper.schema
|
|
341
|
+
- spec/fixtures/sqlite_test_db.sql
|
|
258
342
|
- spec/fixtures/test_db.sql
|
|
343
|
+
- spec/integrations/command_diff.rb
|
|
259
344
|
- spec/integrations/command_dryrun.rb
|
|
345
|
+
- spec/integrations/command_export.rb
|
|
260
346
|
- spec/integrations/drop_foreign_key.rb
|
|
347
|
+
- spec/postgres_integrations/command_dryrun.rb
|
|
261
348
|
- spec/spec_helper.rb
|
|
349
|
+
- spec/sqlite_integrations/command_dryrun.rb
|