sbf-dm-migrations 1.3.0.beta
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 +7 -0
- data/.gitignore +38 -0
- data/.rspec +1 -0
- data/.rubocop.yml +468 -0
- data/.travis.yml +52 -0
- data/Gemfile +61 -0
- data/LICENSE +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +4 -0
- data/db/migrations/1_create_people_table.rb +12 -0
- data/db/migrations/2_add_dob_to_people.rb +13 -0
- data/db/migrations/config.rb +4 -0
- data/dm-migrations.gemspec +20 -0
- data/examples/Rakefile +149 -0
- data/examples/sample_migration.rb +58 -0
- data/examples/sample_migration_spec.rb +46 -0
- data/lib/dm-migrations/adapters/dm-do-adapter.rb +304 -0
- data/lib/dm-migrations/adapters/dm-mysql-adapter.rb +306 -0
- data/lib/dm-migrations/adapters/dm-oracle-adapter.rb +339 -0
- data/lib/dm-migrations/adapters/dm-postgres-adapter.rb +152 -0
- data/lib/dm-migrations/adapters/dm-sqlite-adapter.rb +88 -0
- data/lib/dm-migrations/adapters/dm-sqlserver-adapter.rb +184 -0
- data/lib/dm-migrations/adapters/dm-yaml-adapter.rb +21 -0
- data/lib/dm-migrations/auto_migration.rb +227 -0
- data/lib/dm-migrations/exceptions/duplicate_migration.rb +6 -0
- data/lib/dm-migrations/migration.rb +323 -0
- data/lib/dm-migrations/migration_runner.rb +76 -0
- data/lib/dm-migrations/sql/column.rb +5 -0
- data/lib/dm-migrations/sql/mysql.rb +84 -0
- data/lib/dm-migrations/sql/oracle.rb +9 -0
- data/lib/dm-migrations/sql/postgres.rb +89 -0
- data/lib/dm-migrations/sql/sqlite.rb +59 -0
- data/lib/dm-migrations/sql/sqlserver.rb +9 -0
- data/lib/dm-migrations/sql/table.rb +15 -0
- data/lib/dm-migrations/sql/table_creator.rb +105 -0
- data/lib/dm-migrations/sql/table_modifier.rb +57 -0
- data/lib/dm-migrations/sql.rb +7 -0
- data/lib/dm-migrations/version.rb +5 -0
- data/lib/dm-migrations.rb +3 -0
- data/lib/spec/example/migration_example_group.rb +69 -0
- data/lib/spec/matchers/migration_matchers.rb +96 -0
- data/spec/integration/auto_migration_spec.rb +590 -0
- data/spec/integration/auto_upgrade_spec.rb +41 -0
- data/spec/integration/migration_runner_spec.rb +84 -0
- data/spec/integration/migration_spec.rb +156 -0
- data/spec/integration/sql_spec.rb +290 -0
- data/spec/isolated/require_after_setup_spec.rb +24 -0
- data/spec/isolated/require_before_setup_spec.rb +24 -0
- data/spec/isolated/require_spec.rb +23 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/migration_spec.rb +501 -0
- data/spec/unit/sql/column_spec.rb +14 -0
- data/spec/unit/sql/postgres_spec.rb +90 -0
- data/spec/unit/sql/sqlite_extensions_spec.rb +103 -0
- data/spec/unit/sql/table_creator_spec.rb +91 -0
- data/spec/unit/sql/table_modifier_spec.rb +47 -0
- data/spec/unit/sql/table_spec.rb +26 -0
- data/spec/unit/sql_spec.rb +7 -0
- data/tasks/spec.rake +21 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +120 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe 'SQL module' do
|
4
|
+
describe 'TableCreator' do
|
5
|
+
before do
|
6
|
+
@adapter = instance_double('adapter')
|
7
|
+
allow(@adapter).to receive(:quote_name).and_return(%('users'))
|
8
|
+
@tc = SQL::TableCreator.new(@adapter, 'users') { }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'initialization' do
|
12
|
+
it 'sets @adapter to the adapter' do
|
13
|
+
expect(@tc.instance_variable_get('@adapter')).to eq @adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets @table_name to the stringified table name' do
|
17
|
+
expect(@tc.instance_variable_get('@table_name')).to eq 'users'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets @opts to the options hash' do
|
21
|
+
expect(@tc.instance_variable_get('@opts')).to eq {}
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets @columns to an empty array' do
|
25
|
+
expect(@tc.instance_variable_get('@columns')).to eq []
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'evaluates the given block' do
|
29
|
+
block = proc { column :foo, :bar }
|
30
|
+
col = instance_double('column')
|
31
|
+
expect(SQL::TableCreator::Column).to receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
|
32
|
+
tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
|
33
|
+
expect(tc.instance_variable_get('@columns')).to eq [col]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has a table_name' do
|
38
|
+
expect(@tc).to respond_to(:table_name)
|
39
|
+
expect(@tc.table_name).to eq 'users'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'uses the adapter to quote the table name' do
|
43
|
+
expect(@adapter).to receive(:quote_name).with('users').and_return(%('users'))
|
44
|
+
expect(@tc.quoted_table_name).to eq %('users')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'initializes a new column and add it to the list of columns' do
|
48
|
+
col = instance_double('column')
|
49
|
+
expect(SQL::TableCreator::Column).to receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
|
50
|
+
@tc.column(:foo, :bar)
|
51
|
+
expect(@tc.instance_variable_get('@columns')).to eq [col]
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'outputs an SQL CREATE statement to build itself' do
|
55
|
+
allow(@adapter).to receive(:table_options).and_return('')
|
56
|
+
expect(@tc.to_sql).to eq %{CREATE TABLE 'users' ()}
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Column' do
|
60
|
+
before do
|
61
|
+
connection = instance_double('Connection')
|
62
|
+
|
63
|
+
allow(@adapter).to receive(:quote_column_name).and_return(%('id'))
|
64
|
+
allow(@adapter.class).to receive(:type_map).and_return(Integer => {type: 'int'})
|
65
|
+
allow(@adapter.class).to receive(:type_by_property_class).and_return(Integer => {type: 'int'})
|
66
|
+
allow(@adapter).to receive(:property_schema_statement).and_return('SOME SQL')
|
67
|
+
allow(@adapter).to receive(:with_connection).and_yield(connection)
|
68
|
+
@c = SQL::TableCreator::Column.new(@adapter, 'id', Integer, :serial => true)
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'initialization' do
|
72
|
+
it 'sets @adapter to the adapter' do
|
73
|
+
expect(@c.instance_variable_get('@adapter')).to eq @adapter
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets @name to the stringified name' do
|
77
|
+
expect(@c.instance_variable_get('@name')).to eq 'id'
|
78
|
+
end
|
79
|
+
|
80
|
+
# TODO make this really the type, not this sql bullshit
|
81
|
+
it 'sets @type to the type' do
|
82
|
+
expect(@c.instance_variable_get('@type')).to eq 'SOME SQL'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'sets @opts to the options hash' do
|
86
|
+
expect(@c.instance_variable_get('@opts')).to eq({serial: true})
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe 'SQL module' do
|
4
|
+
describe 'TableModifier' do
|
5
|
+
before do
|
6
|
+
@adapter = instance_double('adapter')
|
7
|
+
allow(@adapter).to receive(:quote_name).and_return(%('users'))
|
8
|
+
@tc = SQL::TableModifier.new(@adapter, :users) { }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'initialization' do
|
12
|
+
it 'sets @adapter to the adapter' do
|
13
|
+
expect(@tc.instance_variable_get('@adapter')).to eq @adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets @table_name to the stringified table name' do
|
17
|
+
expect(@tc.instance_variable_get('@table_name')).to eq 'users'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets @opts to the options hash' do
|
21
|
+
expect(@tc.instance_variable_get('@opts')).to eq({})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets @statements to an empty array' do
|
25
|
+
expect(@tc.instance_variable_get('@statements')).to eq []
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'evaluates the given block' do
|
29
|
+
block = proc { column :foo, :bar }
|
30
|
+
col = instance_double('column')
|
31
|
+
expect(SQL::TableCreator::Column).to receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
|
32
|
+
tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
|
33
|
+
expect(tc.instance_variable_get('@columns')).to eq [col]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has a table_name' do
|
38
|
+
expect(@tc).to respond_to(:table_name)
|
39
|
+
expect(@tc.table_name).to eq 'users'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'uses the adapter to quote the table name' do
|
43
|
+
expect(@adapter).to receive(:quote_name).with('users').and_return(%('users'))
|
44
|
+
expect(@tc.quoted_table_name).to eq %('users')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe SQL::Table do
|
4
|
+
before do
|
5
|
+
@table = SQL::Table.new
|
6
|
+
end
|
7
|
+
|
8
|
+
%w{name columns}.each do |meth|
|
9
|
+
it "has a ##{meth} attribute" do
|
10
|
+
expect(@table).to respond_to(meth.intern)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'uses #to_s for the name' do
|
15
|
+
@table.name = "table_name"
|
16
|
+
expect(@table.to_s).to eq 'table_name'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'finds a column by name' do
|
20
|
+
column_a = double('column', :name => 'id')
|
21
|
+
column_b = double('column', :name => 'login')
|
22
|
+
@table.columns = [column_a, column_b]
|
23
|
+
|
24
|
+
expect(@table.column('id')).to eq column_a
|
25
|
+
end
|
26
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
|
3
|
+
begin
|
4
|
+
task(:default).clear
|
5
|
+
task(:spec).clear
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
9
|
+
|
10
|
+
require 'simplecov'
|
11
|
+
SimpleCov.start do
|
12
|
+
minimum_coverage 100
|
13
|
+
end
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
task :spec do
|
17
|
+
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task default: :spec
|
data/tasks/yard.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'pathname'
|
3
|
+
require 'yardstick/rake/measurement'
|
4
|
+
require 'yardstick/rake/verify'
|
5
|
+
|
6
|
+
# yardstick_measure task
|
7
|
+
Yardstick::Rake::Measurement.new
|
8
|
+
|
9
|
+
# verify_measurements task
|
10
|
+
Yardstick::Rake::Verify.new do |verify|
|
11
|
+
verify.threshold = 100
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
%w(yardstick_measure verify_measurements).each do |name|
|
15
|
+
task name.to_s do
|
16
|
+
abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sbf-dm-migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Kubb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sbf-dm-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0.beta
|
27
|
+
description: DataMapper plugin for modifying and maintaining database structure, triggers,
|
28
|
+
stored procedures, and data
|
29
|
+
email:
|
30
|
+
- dan.kubb@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files:
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
files:
|
37
|
+
- ".gitignore"
|
38
|
+
- ".rspec"
|
39
|
+
- ".rubocop.yml"
|
40
|
+
- ".travis.yml"
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
- Rakefile
|
45
|
+
- db/migrations/1_create_people_table.rb
|
46
|
+
- db/migrations/2_add_dob_to_people.rb
|
47
|
+
- db/migrations/config.rb
|
48
|
+
- dm-migrations.gemspec
|
49
|
+
- examples/Rakefile
|
50
|
+
- examples/sample_migration.rb
|
51
|
+
- examples/sample_migration_spec.rb
|
52
|
+
- lib/dm-migrations.rb
|
53
|
+
- lib/dm-migrations/adapters/dm-do-adapter.rb
|
54
|
+
- lib/dm-migrations/adapters/dm-mysql-adapter.rb
|
55
|
+
- lib/dm-migrations/adapters/dm-oracle-adapter.rb
|
56
|
+
- lib/dm-migrations/adapters/dm-postgres-adapter.rb
|
57
|
+
- lib/dm-migrations/adapters/dm-sqlite-adapter.rb
|
58
|
+
- lib/dm-migrations/adapters/dm-sqlserver-adapter.rb
|
59
|
+
- lib/dm-migrations/adapters/dm-yaml-adapter.rb
|
60
|
+
- lib/dm-migrations/auto_migration.rb
|
61
|
+
- lib/dm-migrations/exceptions/duplicate_migration.rb
|
62
|
+
- lib/dm-migrations/migration.rb
|
63
|
+
- lib/dm-migrations/migration_runner.rb
|
64
|
+
- lib/dm-migrations/sql.rb
|
65
|
+
- lib/dm-migrations/sql/column.rb
|
66
|
+
- lib/dm-migrations/sql/mysql.rb
|
67
|
+
- lib/dm-migrations/sql/oracle.rb
|
68
|
+
- lib/dm-migrations/sql/postgres.rb
|
69
|
+
- lib/dm-migrations/sql/sqlite.rb
|
70
|
+
- lib/dm-migrations/sql/sqlserver.rb
|
71
|
+
- lib/dm-migrations/sql/table.rb
|
72
|
+
- lib/dm-migrations/sql/table_creator.rb
|
73
|
+
- lib/dm-migrations/sql/table_modifier.rb
|
74
|
+
- lib/dm-migrations/version.rb
|
75
|
+
- lib/spec/example/migration_example_group.rb
|
76
|
+
- lib/spec/matchers/migration_matchers.rb
|
77
|
+
- spec/integration/auto_migration_spec.rb
|
78
|
+
- spec/integration/auto_upgrade_spec.rb
|
79
|
+
- spec/integration/migration_runner_spec.rb
|
80
|
+
- spec/integration/migration_spec.rb
|
81
|
+
- spec/integration/sql_spec.rb
|
82
|
+
- spec/isolated/require_after_setup_spec.rb
|
83
|
+
- spec/isolated/require_before_setup_spec.rb
|
84
|
+
- spec/isolated/require_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/unit/migration_spec.rb
|
87
|
+
- spec/unit/sql/column_spec.rb
|
88
|
+
- spec/unit/sql/postgres_spec.rb
|
89
|
+
- spec/unit/sql/sqlite_extensions_spec.rb
|
90
|
+
- spec/unit/sql/table_creator_spec.rb
|
91
|
+
- spec/unit/sql/table_modifier_spec.rb
|
92
|
+
- spec/unit/sql/table_spec.rb
|
93
|
+
- spec/unit/sql_spec.rb
|
94
|
+
- tasks/spec.rake
|
95
|
+
- tasks/yard.rake
|
96
|
+
- tasks/yardstick.rake
|
97
|
+
homepage: https://datamapper.org
|
98
|
+
licenses:
|
99
|
+
- Nonstandard
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.7.8
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.3.1
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.4.10
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: DataMapper plugin for writing and spec-ing migrations
|
120
|
+
test_files: []
|