declare_schema 2.0.0 → 2.1.0.pre.1

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/.devcontainer/Dockerfile +19 -0
  3. data/.devcontainer/boot.sh +1 -0
  4. data/.devcontainer/devcontainer.json +55 -0
  5. data/.devcontainer/docker-compose.yml +40 -0
  6. data/.github/workflows/declare_schema_build.yml +35 -11
  7. data/Appraisals +2 -10
  8. data/CHANGELOG.md +5 -0
  9. data/CODE-OF-CONDUCT.md +16 -0
  10. data/CONTRIBUTING.md +46 -0
  11. data/Gemfile +6 -1
  12. data/Gemfile.lock +87 -77
  13. data/README.md +38 -14
  14. data/Rakefile +5 -15
  15. data/catalog-info.yaml +35 -0
  16. data/config/brakeman.ignore +2 -2
  17. data/gemfiles/{rails_6_1_sqlite3.gemfile → rails_6_1.gemfile} +3 -0
  18. data/gemfiles/{rails_7_0_sqlite3.gemfile → rails_7_0.gemfile} +3 -0
  19. data/gemfiles/{rails_7_1_sqlite3.gemfile → rails_7_1.gemfile} +3 -0
  20. data/gemfiles/{rails_7_0_mysql2.gemfile → rails_7_2.gemfile} +4 -1
  21. data/lib/declare_schema/command.rb +2 -8
  22. data/lib/declare_schema/model/column.rb +1 -1
  23. data/lib/declare_schema/model/foreign_key_definition.rb +9 -12
  24. data/lib/declare_schema/model/index_definition.rb +16 -8
  25. data/lib/declare_schema/model.rb +10 -14
  26. data/lib/declare_schema/schema_change/base.rb +4 -0
  27. data/lib/declare_schema/schema_change/primary_key_change.rb +19 -6
  28. data/lib/declare_schema/version.rb +1 -1
  29. data/lib/declare_schema.rb +20 -8
  30. data/lib/generators/declare_schema/migration/migration_generator.rb +15 -2
  31. data/lib/generators/declare_schema/migration/migrator.rb +16 -9
  32. data/spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_6.txt +15 -0
  33. data/spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_7.txt +15 -0
  34. data/spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_6.txt +15 -0
  35. data/spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_7.txt +15 -0
  36. data/spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_6.txt +15 -0
  37. data/spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_7.txt +15 -0
  38. data/spec/lib/declare_schema/api_spec.rb +1 -3
  39. data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +3 -3
  40. data/spec/lib/declare_schema/field_spec_spec.rb +68 -45
  41. data/spec/lib/declare_schema/generator_spec.rb +2 -4
  42. data/spec/lib/declare_schema/interactive_primary_key_spec.rb +3 -10
  43. data/spec/lib/declare_schema/migration_generator_spec.rb +248 -249
  44. data/spec/lib/declare_schema/model/column_spec.rb +89 -41
  45. data/spec/lib/declare_schema/model/foreign_key_definition_spec.rb +14 -8
  46. data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +4 -9
  47. data/spec/lib/declare_schema/model/index_definition_spec.rb +18 -10
  48. data/spec/lib/declare_schema/model/table_options_definition_spec.rb +11 -11
  49. data/spec/lib/declare_schema/schema_change/base_spec.rb +5 -7
  50. data/spec/lib/declare_schema/schema_change/column_add_spec.rb +1 -3
  51. data/spec/lib/declare_schema/schema_change/column_change_spec.rb +1 -3
  52. data/spec/lib/declare_schema/schema_change/column_remove_spec.rb +1 -3
  53. data/spec/lib/declare_schema/schema_change/column_rename_spec.rb +1 -3
  54. data/spec/lib/declare_schema/schema_change/foreign_key_add_spec.rb +1 -3
  55. data/spec/lib/declare_schema/schema_change/foreign_key_remove_spec.rb +1 -3
  56. data/spec/lib/declare_schema/schema_change/index_add_spec.rb +1 -3
  57. data/spec/lib/declare_schema/schema_change/index_remove_spec.rb +1 -3
  58. data/spec/lib/declare_schema/schema_change/primary_key_change_spec.rb +39 -15
  59. data/spec/lib/declare_schema/schema_change/table_add_spec.rb +1 -3
  60. data/spec/lib/declare_schema/schema_change/table_change_spec.rb +1 -3
  61. data/spec/lib/declare_schema/schema_change/table_remove_spec.rb +1 -3
  62. data/spec/lib/declare_schema/schema_change/table_rename_spec.rb +1 -3
  63. data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +0 -4
  64. data/spec/spec_helper.rb +3 -0
  65. data/spec/support/adapter_specific_test_helpers.rb +25 -0
  66. data/spec/{lib/declare_schema → support}/prepare_testapp.rb +3 -1
  67. data/spec/support/test_app_spec_helpers.rb +7 -0
  68. metadata +22 -9
  69. data/gemfiles/rails_6_1_mysql2.gemfile +0 -23
  70. data/gemfiles/rails_7_1_mysql2.gemfile +0 -23
@@ -3,9 +3,7 @@
3
3
  require_relative '../../../../lib/declare_schema/schema_change/table_remove'
4
4
 
5
5
  RSpec.describe DeclareSchema::SchemaChange::TableRemove do
6
- before do
7
- load File.expand_path('../prepare_testapp.rb', __dir__)
8
- end
6
+ include_context 'prepare test app'
9
7
 
10
8
  let(:table_name) { 'networks' }
11
9
  let(:add_table_back) { "create table networks(\n)" }
@@ -3,9 +3,7 @@
3
3
  require_relative '../../../../lib/declare_schema/schema_change/table_rename'
4
4
 
5
5
  RSpec.describe DeclareSchema::SchemaChange::TableRename do
6
- before do
7
- load File.expand_path('../prepare_testapp.rb', __dir__)
8
- end
6
+ include_context 'prepare test app'
9
7
 
10
8
  let(:old_name) { 'networks' }
11
9
  let(:new_name) { 'customers' }
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
4
- require 'mysql2'
5
- rescue LoadError
6
- end
7
3
  require 'rails'
8
4
  require 'rails/generators'
9
5
  require 'generators/declare_schema/migration/migrator'
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,11 @@ require 'bundler/setup'
4
4
  require 'declare_schema'
5
5
  require 'climate_control'
6
6
  require 'pry'
7
+ require 'rspec/its'
7
8
 
8
9
  require_relative "./support/acceptance_spec_helpers"
10
+ require_relative "./support/adapter_specific_test_helpers"
11
+ require_relative "./support/test_app_spec_helpers"
9
12
 
10
13
  RSpec.configure do |config|
11
14
  config.include AcceptanceSpecHelpers
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context 'skip if' do
4
+ around do |spec|
5
+ if current_adapter == adapter
6
+ spec.skip
7
+ else
8
+ spec.run
9
+ end
10
+ end
11
+ end
12
+
13
+ RSpec.shared_context 'skip unless' do
14
+ around do |spec|
15
+ if current_adapter != adapter
16
+ spec.skip
17
+ else
18
+ spec.run
19
+ end
20
+ end
21
+ end
22
+
23
+ def current_adapter(model_class = ActiveRecord::Base)
24
+ DeclareSchema.current_adapter(model_class)
25
+ end
@@ -21,7 +21,9 @@ Rails::Generators.configure!(Rails.application.config.generators)
21
21
  ActiveRecord::Base.connection.schema_cache.clear!
22
22
 
23
23
  (ActiveRecord::Base.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables).each do |table|
24
- ActiveRecord::Base.connection.execute("DROP TABLE #{ActiveRecord::Base.connection.quote_table_name(table)}")
24
+ ActiveRecord::Base.connection.execute("SET FOREIGN_KEY_CHECKS = 0") rescue nil # rubocop:disable Style/RescueModifier
25
+ ActiveRecord::Base.connection.execute("DROP TABLE #{ActiveRecord::Base.connection.quote_table_name(table)} #{current_adapter != 'sqlite3' ? 'CASCADE': ''}")
26
+ ActiveRecord::Base.connection.execute("SET FOREIGN_KEY_CHECKS = 1") rescue nil # rubocop:disable Style/RescueModifier
25
27
  end
26
28
 
27
29
  ActiveRecord::Base.send(:descendants).each do |model|
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context 'prepare test app' do
4
+ before do
5
+ load File.expand_path('./prepare_testapp.rb', __dir__)
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: declare_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-14 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -32,6 +32,10 @@ executables:
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".devcontainer/Dockerfile"
36
+ - ".devcontainer/boot.sh"
37
+ - ".devcontainer/devcontainer.json"
38
+ - ".devcontainer/docker-compose.yml"
35
39
  - ".github/CODEOWNERS"
36
40
  - ".github/workflows/declare_schema_build.yml"
37
41
  - ".github/workflows/gem_release.yml"
@@ -41,21 +45,22 @@ files:
41
45
  - ".ruby-version"
42
46
  - Appraisals
43
47
  - CHANGELOG.md
48
+ - CODE-OF-CONDUCT.md
49
+ - CONTRIBUTING.md
44
50
  - Gemfile
45
51
  - Gemfile.lock
46
52
  - LICENSE.txt
47
53
  - README.md
48
54
  - Rakefile
49
55
  - bin/declare_schema
56
+ - catalog-info.yaml
50
57
  - config/brakeman.ignore
51
58
  - declare_schema.gemspec
52
59
  - gemfiles/.bundle/config
53
- - gemfiles/rails_6_1_mysql2.gemfile
54
- - gemfiles/rails_6_1_sqlite3.gemfile
55
- - gemfiles/rails_7_0_mysql2.gemfile
56
- - gemfiles/rails_7_0_sqlite3.gemfile
57
- - gemfiles/rails_7_1_mysql2.gemfile
58
- - gemfiles/rails_7_1_sqlite3.gemfile
60
+ - gemfiles/rails_6_1.gemfile
61
+ - gemfiles/rails_7_0.gemfile
62
+ - gemfiles/rails_7_1.gemfile
63
+ - gemfiles/rails_7_2.gemfile
59
64
  - lib/declare_schema.rb
60
65
  - lib/declare_schema/command.rb
61
66
  - lib/declare_schema/dsl.rb
@@ -96,6 +101,12 @@ files:
96
101
  - lib/generators/declare_schema/support/eval_template.rb
97
102
  - lib/generators/declare_schema/support/model.rb
98
103
  - lib/generators/declare_schema/support/thor_shell.rb
104
+ - spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_6.txt
105
+ - spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_7.txt
106
+ - spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_6.txt
107
+ - spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_7.txt
108
+ - spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_6.txt
109
+ - spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_7.txt
99
110
  - spec/lib/declare_schema/api_spec.rb
100
111
  - spec/lib/declare_schema/field_declaration_dsl_spec.rb
101
112
  - spec/lib/declare_schema/field_spec_spec.rb
@@ -107,7 +118,6 @@ files:
107
118
  - spec/lib/declare_schema/model/habtm_model_shim_spec.rb
108
119
  - spec/lib/declare_schema/model/index_definition_spec.rb
109
120
  - spec/lib/declare_schema/model/table_options_definition_spec.rb
110
- - spec/lib/declare_schema/prepare_testapp.rb
111
121
  - spec/lib/declare_schema/schema_change/base_spec.rb
112
122
  - spec/lib/declare_schema/schema_change/column_add_spec.rb
113
123
  - spec/lib/declare_schema/schema_change/column_change_spec.rb
@@ -126,6 +136,9 @@ files:
126
136
  - spec/lib/generators/declare_schema/migration/migrator_spec.rb
127
137
  - spec/spec_helper.rb
128
138
  - spec/support/acceptance_spec_helpers.rb
139
+ - spec/support/adapter_specific_test_helpers.rb
140
+ - spec/support/prepare_testapp.rb
141
+ - spec/support/test_app_spec_helpers.rb
129
142
  homepage: https://github.com/Invoca/declare_schema
130
143
  licenses: []
131
144
  metadata:
@@ -1,23 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "climate_control", "~> 0.2"
7
- gem "mail"
8
- gem "net-smtp"
9
- gem "pry"
10
- gem "pry-byebug"
11
- gem "rails", "~> 6.1.0"
12
- gem "responders"
13
- gem "rspec"
14
- gem "rubocop"
15
- gem "yard"
16
- gem "mysql2", "~> 0.5"
17
-
18
- group :testapp do
19
- gem "bootsnap", ">= 1.1.0", require: false
20
- gem "listen"
21
- end
22
-
23
- gemspec path: "../"
@@ -1,23 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "climate_control", "~> 0.2"
7
- gem "mail"
8
- gem "net-smtp"
9
- gem "pry"
10
- gem "pry-byebug"
11
- gem "rails", "~> 7.1.0"
12
- gem "responders"
13
- gem "rspec"
14
- gem "rubocop"
15
- gem "yard"
16
- gem "mysql2", "~> 0.5"
17
-
18
- group :testapp do
19
- gem "bootsnap", ">= 1.1.0", require: false
20
- gem "listen"
21
- end
22
-
23
- gemspec path: "../"