standalone_migrations 7.1.1 → 7.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66f87cd3256a662758f0fd259e5f70041cb7d66bd9c291bf40ba6b48786fa437
4
- data.tar.gz: 54ffbe0be9e3122eaa6ba568448ce62f80bff8f0005308417b47e67e45aa3d71
3
+ metadata.gz: aa4253d853dda697a79a89168930f03f2cd24faf8735b3c74160052ed4af42cd
4
+ data.tar.gz: 9134409f5c61cb61aa8eea4c0f8de328e46f5bf6ac8b91001252c224da72b859
5
5
  SHA512:
6
- metadata.gz: cdfe6fcfdd99b9586126daa36c9772479f7872bab6755cf6daeeef0aa8cd3695154a37e9bd9d15ee49ed18317d7f02d7010206afe55e2cd88309d39ba2164f92
7
- data.tar.gz: 87c736c8d019bb2b9d36b628f220902e4f77e20ef7cf866ae6bc6ba00e4453dcf09a5f4d520598e222266bda03d09845fdfeadf3db6fbf87d0a74b6bde960a13
6
+ metadata.gz: e3f45a0a083c645cefb4adf7518fcdef10304f5a742e6ed167da2e5353b687b9bf957d9880ff216c17f13197c21afa55f2a9cd5c63f80ae3e288c434450a76ce
7
+ data.tar.gz: '05090f7bfbbefaf86ca4026b2b000e3efb7460e03aa7ea66554cf6444462ec04c518788fe9ed7ae545c914d062580144b1430eca7876d221446be5a0a7c79c21'
@@ -0,0 +1,34 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby:
16
+ - '2.7'
17
+ - '3.0'
18
+ - '3.1'
19
+ activerecord:
20
+ - '6.0'
21
+ - '6.1'
22
+ - '7.0'
23
+ - '7.1'
24
+ name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.activerecord }}
25
+ env:
26
+ AR: ~> ${{ matrix.activerecord }}
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ bundler-cache: true
33
+ - run: |
34
+ bundle exec rake
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
1
+ --force-color
2
2
  --profile
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake', '>= 10.0'
4
- gem 'activerecord', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
5
- gem 'railties', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
4
+ gem 'activerecord', ENV['AR'] ? ENV['AR'].split(",") : [">= 6.0.0", "< 7.2"]
5
+ gem 'railties', ENV['AR'] ? ENV['AR'].split(",") : [">= 6.0.0", "< 7.2"]
6
+ gem 'nokogiri', "~> 1.14"
6
7
 
7
8
  group :dev do
8
- gem 'sqlite3', ENV['SQL'] ? ENV['SQL'].split(",") : ['~> 1.4']
9
+ gem 'sqlite3', '~> 1.5'
9
10
  gem 'rspec', '>= 2.99.0'
10
11
  gem 'jeweler'
11
12
  end
data/README.markdown CHANGED
@@ -1,9 +1,11 @@
1
1
  Rails migrations in non-Rails (and non Ruby) projects.
2
2
 
3
- [![Build Status](https://travis-ci.org/thuss/standalone-migrations.svg?branch=master)](https://travis-ci.org/thuss/standalone-migrations)
3
+ [![Build Status](https://github.com/thuss/standalone-migrations/actions/workflows/CI.yml/badge.svg)](https://github.com/thuss/standalone-migrations/actions)
4
4
 
5
5
  WHAT'S NEW
6
6
  ==========
7
+ In the 7.x release we've added support for Rails 7 migrations thanks to multiple community submitted PR's!
8
+
7
9
  In the 6.x release we've added support for Rails 6 migrations thanks to [Marco Adkins](https://github.com/marcoadkins).
8
10
 
9
11
  In the 5.x release we have moved to using Rails 5 migrations instead of maintaining our own migration related code. Just about anything you can do with Rails 5 migrations you can now do with [Standalone Migrations](https://github.com/thuss/standalone-migrations) too!
@@ -18,6 +20,15 @@ Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql` or `
18
20
 
19
21
  $ gem install standalone_migrations
20
22
 
23
+ or use a Gemfile (and then `bundle install`):
24
+
25
+ ```
26
+ source 'https://rubygems.org'
27
+
28
+ gem 'standalone_migrations'
29
+ gem 'pg' # or mysql2
30
+ ```
31
+
21
32
  Add to `Rakefile` in your projects base directory:
22
33
 
23
34
  ```ruby
@@ -271,3 +282,5 @@ Contributors
271
282
  - [Marco Adkins](https://github.com/marcoadkins)
272
283
  - [Mithun James](https://github.com/drtechie)
273
284
  - [Sarah Ridge](https://github.com/smridge)
285
+ - [John Bachir](https://jjb.cc)
286
+ - [Pysis](https://github.com/Pysis868)
data/Rakefile CHANGED
@@ -1,32 +1,16 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- task :default do
5
- sh "rspec spec"
6
- end
7
-
8
4
  task :all do
9
5
  sh "AR='~>3.0.0' bundle update activerecord && bundle exec rake"
10
6
  sh "AR='~>3.1.0.rc4' bundle update activerecord && bundle exec rake"
11
7
  end
12
8
 
13
- task :specs => ["specs:nodb"]
14
- namespace :specs do
9
+ begin
15
10
  require 'rspec/core/rake_task'
16
-
17
- desc "only specs that don't use database connection"
18
- RSpec::Core::RakeTask.new "nodb" do |t|
19
- t.pattern = "spec/standalone_migrations/**/*_spec.rb"
20
- end
21
-
22
- desc "run all specs for travis"
23
- RSpec::Core::RakeTask.new "travis" do |t|
24
- t.pattern = "spec/**/*_spec.rb"
25
- t.rspec_opts = "--tag ~@travis_error"
26
- end
27
-
28
- desc "run all specs including those which uses database"
29
- task :all => [:default, :nodb]
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ rescue LoadError
13
+ # no rspec available
30
14
  end
31
15
 
32
16
  # rake install -> install gem locally (for tests)
@@ -50,3 +34,5 @@ else
50
34
 
51
35
  Jeweler::GemcutterTasks.new
52
36
  end
37
+
38
+ task default: "spec"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.1.1
1
+ 7.1.3
data/example/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '~> 3.0'
4
+
5
+ gem 'standalone_migrations'
6
+ gem 'sqlite3'
@@ -0,0 +1,23 @@
1
+ This is an example minimal app based off of
2
+ [this blog post](https://www.techcareerbooster.com/blog/use-activerecord-in-your-ruby-project),
3
+ archived [here](article.pdf) with permission of the author.
4
+
5
+ It demonstrates:
6
+
7
+ * database configuration
8
+ * a migration
9
+ * a model
10
+ * loading all relevant code into a runtime and using it
11
+
12
+
13
+ ```
14
+ bundle
15
+ bundle exec rake db:create
16
+ bundle exec rake db:migrate
17
+ bundle exec irb -r ./boot.rb
18
+ ```
19
+
20
+ ```ruby
21
+ Movie.create! title: "Attack of the Cats", director: "Furball McCat"
22
+ Movie.count
23
+ ```
data/example/Rakefile CHANGED
@@ -1,9 +1,2 @@
1
- # $LOAD_PATH handling not need if the standalone_migrations
2
- # gem is installed
3
- lib = File.expand_path("../../lib", __FILE__)
4
- $:.unshift lib unless $:.include?(lib)
5
-
6
- require "standalone_migrations"
1
+ require 'standalone_migrations'
7
2
  StandaloneMigrations::Tasks.load_tasks
8
-
9
- # and that's it!
@@ -0,0 +1,4 @@
1
+ class Movie < ActiveRecord::Base
2
+ validates :title, presence: true, uniqueness: {case_insensitive: true}
3
+ validates :director, presence: true
4
+ end
Binary file
data/example/boot.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'active_record'
2
+ require_relative './app/models/movie'
3
+
4
+ def db_configuration
5
+ db_configuration_file = File.join(File.expand_path('..', __FILE__), '.', 'db', 'config.yml')
6
+ YAML.load(File.read(db_configuration_file))
7
+ end
8
+
9
+ ActiveRecord::Base.establish_connection(db_configuration["development"])
@@ -0,0 +1 @@
1
+ *.sqlite3
@@ -0,0 +1,11 @@
1
+ class CreateMovies < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :movies do |t|
4
+ t.string :title, null: false
5
+ t.string :director, null: false
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2021_02_02_023614) do
14
+
15
+ create_table "movies", force: :cascade do |t|
16
+ t.string "title", null: false
17
+ t.string "director", null: false
18
+ t.datetime "created_at", precision: 6, null: false
19
+ t.datetime "updated_at", precision: 6, null: false
20
+ end
21
+
22
+ end
@@ -2,7 +2,6 @@ require 'active_support/all'
2
2
  require 'yaml'
3
3
 
4
4
  module StandaloneMigrations
5
-
6
5
  class InternalConfigurationsProxy
7
6
 
8
7
  attr_reader :configurations
@@ -32,72 +31,100 @@ module StandaloneMigrations
32
31
  end
33
32
 
34
33
  def initialize(options = {})
35
- default_schema = ENV['SCHEMA'] || ActiveRecord::Tasks::DatabaseTasks.schema_file(ActiveRecord::Base.schema_format)
36
- defaults = {
37
- :config => "db/config.yml",
38
- :migrate_dir => "db/migrate",
39
- :root => Pathname.pwd,
40
- :seeds => "db/seeds.rb",
41
- :schema => default_schema
42
- }
43
- @options = load_from_file(defaults.dup) || defaults.merge(options)
34
+ options = options.dup
35
+ @schema = options.delete('schema')
36
+ @config_overrides = defaults
37
+ c_os['paths'].merge!(options.delete('paths') || {})
38
+ c_os.merge!(options)
44
39
 
45
- ENV['SCHEMA'] = schema
46
- Rails.application.config.root = root
47
- Rails.application.config.paths["config/database"] = config
48
- Rails.application.config.paths["db/migrate"] = migrate_dir
49
- Rails.application.config.paths["db/seeds.rb"] = seeds
50
- end
40
+ load_from_file
41
+
42
+ ENV['SCHEMA'] ||= @schema if @schema
43
+ rac = Rails.application.config
51
44
 
52
- def config
53
- @options[:config]
45
+ rac.root = c_os['root']
46
+ c_os['paths'].each do |path, value|
47
+ rac.paths[path] = value
48
+ end
54
49
  end
55
50
 
56
- def migrate_dir
57
- @options[:migrate_dir]
51
+ def config_for_all
52
+ Configurator.load_configurations.dup
58
53
  end
59
54
 
60
- def root
61
- @options[:root]
55
+ def config_for(environment)
56
+ config_for_all[environment.to_s]
62
57
  end
63
58
 
64
- def seeds
65
- @options[:seeds]
59
+ def c_os
60
+ config_overrides
61
+ end
62
+ def config_overrides
63
+ @config_overrides
66
64
  end
67
65
 
68
- def schema
69
- @options[:schema]
66
+ def c_o_p_m
67
+ config_override_path_mappings
68
+ end
69
+ def config_override_path_mappings
70
+ {
71
+ 'config/database' => {
72
+ 'config_key_path' => ['config', 'database'],
73
+ 'default' => 'db/config.yml'
74
+ },
75
+ 'db' => {
76
+ 'config_key_path' => ['db' , 'dir' ],
77
+ 'default' => 'db'
78
+ },
79
+ 'db/migrate' => {
80
+ 'config_key_path' => ['db' , 'migrate' ],
81
+ 'default' => 'db/migrate'
82
+ },
83
+ 'db/seeds.rb' => {
84
+ 'config_key_path' => ['db' , 'seeds' ],
85
+ 'default' => 'db/seeds.rb'
86
+ },
87
+ }
70
88
  end
71
89
 
72
- def config_for_all
73
- Configurator.load_configurations.dup
90
+ def defaults
91
+ {
92
+ 'paths' => c_o_p_m.map do |path, value|
93
+ [ path, value['default'] ]
94
+ end.to_h,
95
+ 'root' => Pathname.pwd,
96
+ }
74
97
  end
75
98
 
76
- def config_for(environment)
77
- config_for_all[environment.to_s]
99
+ def schema
100
+ @schema
78
101
  end
79
102
 
80
103
  private
81
104
 
82
105
  def configuration_file
83
- if !ENV['DATABASE']
84
- ".standalone_migrations"
85
- else
86
- ".#{ENV['DATABASE']}.standalone_migrations"
87
- end
106
+ ".#{ENV['DATABASE']}.standalone_migrations".sub(/^\.\./, '.')
88
107
  end
89
108
 
90
- def load_from_file(defaults)
109
+ def load_from_file
91
110
  return nil unless File.exist? configuration_file
92
- config = YAML.load( ERB.new(IO.read(configuration_file)).result )
93
- {
94
- :config => config["config"] ? config["config"]["database"] : defaults[:config],
95
- :migrate_dir => (config["db"] || {})["migrate"] || defaults[:migrate_dir],
96
- :root => config["root"] || defaults[:root],
97
- :seeds => (config["db"] || {})["seeds"] || defaults[:seeds],
98
- :schema => (config["db"] || {})["schema"] || defaults[:schema]
99
- }
100
- end
111
+ data = YAML.load( ERB.new(IO.read(configuration_file)).result )
112
+
113
+ @schema = data.dig('db', 'schema')
101
114
 
115
+ c_o_paths = c_o_p_m.map do |path, value|
116
+ [
117
+ path,
118
+ data.dig(*value['config_key_path'])
119
+ ]
120
+ end.to_h.select { |key, value| value.present? }
121
+
122
+ c_o_paths = defaults['paths'].merge(c_o_paths)
123
+
124
+ @config_overrides = defaults.merge({
125
+ 'paths' => c_o_paths,
126
+ 'root' => data.dig('root'),
127
+ }.select { |key, value| value.present? })
128
+ end
102
129
  end
103
130
  end
@@ -4,30 +4,62 @@ require 'yaml'
4
4
  module StandaloneMigrations
5
5
  describe Configurator, "which allows define custom dirs and files to work with your migrations" do
6
6
 
7
- describe "environment yaml configuration loading" do
7
+ around(:each) do |example|
8
+ Dir.mktmpdir do |dir|
9
+ Dir.chdir(dir) do
10
+ example.run
11
+ end
12
+ end
13
+ end
14
+
15
+ it "does not break / emit an error" do
16
+ expect { Configurator.new }.not_to raise_error
17
+ end
18
+
19
+ context "default values when .standalone_configurations is missing" do
20
+ let(:configurator) do
21
+ Configurator.new
22
+ end
23
+
24
+ it "use config/database.yml" do
25
+ expect(configurator.c_os['paths']['config/database']).to eq('db/config.yml')
26
+ end
27
+
28
+ it "use db dir" do
29
+ expect(configurator.c_os['paths']['db']).to eq('db')
30
+ end
31
+
32
+ it "use db/migrate dir" do
33
+ expect(configurator.c_os['paths']['db/migrate']).to eq('db/migrate')
34
+ end
8
35
 
36
+ it "use db/seeds.rb" do
37
+ expect(configurator.c_os['paths']['db/seeds.rb']).to eq("db/seeds.rb")
38
+ end
39
+ end
40
+
41
+ describe "environment yaml configuration loading" do
9
42
 
10
43
  let(:env_hash_other_db) do
11
44
  {
12
- "development" => { "adapter" => "mysql2", "database" => "database_name" },
13
- "test" => { "adapter" => "mysql2", "database" => "database_name" },
14
- "production" => {"adapter" => "mysql2", "database" => "database_name" }
45
+ "development" => {"adapter" => "mysql2", "database" => "database_name"},
46
+ "test" => {"adapter" => "mysql2", "database" => "database_name"},
47
+ "production" => {"adapter" => "mysql2", "database" => "database_name"}
15
48
  }
16
49
  end
17
50
 
18
- before(:all) do
51
+ around(:each) do |example|
19
52
  @env_hash = {
20
- "development" => { "adapter" => "sqlite3", "database" => "db/development.sql" },
21
- "test" => { "adapter" => "sqlite3", "database" => "db/test.sql" },
22
- "production" => {"adapter" => "sqlite3", "database" => ":memory:" }
53
+ "development" => {"adapter" => "sqlite3", "database" => "db/development.sql"},
54
+ "test" => {"adapter" => "sqlite3", "database" => "db/test.sql" },
55
+ "production" => {"adapter" => "sqlite3", "database" => ":memory:" }
23
56
  }
24
- @original_dir = Dir.pwd
25
- Dir.chdir( File.expand_path("../../", __FILE__) )
26
- FileUtils.mkdir_p "tmp/db"
27
- Dir.chdir "tmp"
57
+ FileUtils.mkdir_p "db"
28
58
  File.open("db/config.yml", "w") do |f|
29
59
  f.write @env_hash.to_yaml
30
60
  end
61
+
62
+ example.run
31
63
  end
32
64
 
33
65
  it "load the specific environment config" do
@@ -49,7 +81,7 @@ module StandaloneMigrations
49
81
  let(:configurator) { Configurator.new }
50
82
 
51
83
  before(:all) do
52
- @new_config = { 'sbrobous' => 'test' }
84
+ @new_config = {'sbrobous' => 'test'}
53
85
  Configurator.environments_config do |env|
54
86
  env.on "production" do
55
87
  @new_config
@@ -80,43 +112,18 @@ module StandaloneMigrations
80
112
 
81
113
  end
82
114
 
83
- after(:all) do
84
- Dir.chdir @original_dir
85
- end
86
-
87
- end
88
-
89
- context "default values when .standalone_configurations is missing" do
90
-
91
- let(:configurator) do
92
- Configurator.new
93
- end
94
-
95
- it "use config/database.yml" do
96
- expect(configurator.config).to eq('db/config.yml')
97
- end
98
-
99
- it "use db/migrate dir" do
100
- expect(configurator.migrate_dir).to eq('db/migrate')
101
- end
102
-
103
- it "use db/seeds.rb" do
104
- expect(configurator.seeds).to eq("db/seeds.rb")
105
- end
106
-
107
- it "use db/schema.rb" do
108
- expect(configurator.schema).to end_with("/db/schema.rb")
109
- end
110
-
111
115
  end
112
116
 
113
117
  context "passing configurations as a parameter" do
114
118
  let(:args) do
115
119
  {
116
- :config => "custom/config/database.yml",
117
- :migrate_dir => "custom/db/migrate",
118
- :seeds => "custom/db/seeds.rb",
119
- :schema => "custom/db/schema.rb"
120
+ 'paths' => {
121
+ 'config/database' => "custom/config/database.yml" ,
122
+ 'db' => "db" ,
123
+ 'db/migrate' => "custom/db/migrate" ,
124
+ 'db/seeds.rb' => "custom/db/seeds.rb" ,
125
+ },
126
+ 'schema' => "custom/db/schema.rb"
120
127
  }
121
128
  end
122
129
 
@@ -125,36 +132,49 @@ module StandaloneMigrations
125
132
  end
126
133
 
127
134
  it "use custom config" do
128
- expect(configurator.config).to eq(args[:config])
135
+ expect(configurator.c_os['paths']['config/database']).to(
136
+ eq(args['paths']['config/database'])
137
+ )
138
+ end
139
+
140
+ it "use custom db dir" do
141
+ expect(configurator.c_os['paths']['db']).to(
142
+ eq(args['paths']['db'])
143
+ )
129
144
  end
130
145
 
131
146
  it "use custom migrate dir" do
132
- expect(configurator.migrate_dir).to eq(args[:migrate_dir])
147
+ expect(configurator.c_os['paths']['db/migrate']).to(
148
+ eq(args['paths']['db/migrate'])
149
+ )
133
150
  end
134
151
 
135
152
  it "use custom seeds" do
136
- expect(configurator.seeds).to eq(args[:seeds])
153
+ expect(configurator.c_os['paths']['db/seeds.rb']).to(
154
+ eq(args['paths']['db/seeds.rb'])
155
+ )
137
156
  end
138
157
 
139
158
  it "use custom schema" do
140
- expect(configurator.schema).to eq(args[:schema])
159
+ expect(configurator.schema).to eq(args['schema'])
141
160
  end
142
161
 
143
162
  end
144
163
 
145
164
  context "using a .standalone_migrations file with configurations" do
146
165
 
147
- before(:all) do
148
- @original_dir = Dir.pwd
149
- Dir.chdir File.expand_path("../", __FILE__)
166
+ before(:each) do
167
+ file = ".standalone_migrations"
168
+ File.open(file, "w") { |file| file.write(yaml_hash.to_yaml) }
150
169
  end
151
170
 
152
171
  let(:yaml_hash) do
153
172
  {
154
173
  "db" => {
155
- "seeds" => "file/db/seeds.rb",
156
- "migrate" => "file/db/migrate",
157
- "schema" => "file/db/schema.rb"
174
+ "dir" => "file/db" ,
175
+ "migrate" => "file/db/migrate" ,
176
+ "seeds" => "file/db/seeds.rb" ,
177
+ "schema" => "file/db/schema.rb"
158
178
  },
159
179
  "config" => {
160
180
  "database" => "file/config/database.yml"
@@ -165,9 +185,10 @@ module StandaloneMigrations
165
185
  let(:yaml_hash_other_db) do
166
186
  {
167
187
  "db" => {
168
- "seeds" => "db2/seeds.rb",
169
- "migrate" => "db2/migrate",
170
- "schema" => "db2/schema.rb"
188
+ "dir" => "db2" ,
189
+ "migrate" => "db2/migrate" ,
190
+ "seeds" => "db2/seeds.rb" ,
191
+ "schema" => "db2/schema.rb"
171
192
  },
172
193
  "config" => {
173
194
  "database" => "config/config_other.yml"
@@ -176,33 +197,36 @@ module StandaloneMigrations
176
197
  end
177
198
 
178
199
  let(:configurator) do
179
- file = ".standalone_migrations"
180
- File.open(file, "w") { |file| file.write(yaml_hash.to_yaml) }
181
200
  Configurator.new
182
201
  end
183
202
 
184
203
  context "with database environment variable passed" do
185
204
 
186
- before(:all) do
205
+ before(:each) do
187
206
  ENV['DATABASE'] = "other_db"
207
+ file_other_db = ".other_db.standalone_migrations"
208
+ File.open(file_other_db, "w") do |file|
209
+ file.write(yaml_hash_other_db.to_yaml)
210
+ end
188
211
  end
189
212
 
190
213
  let(:other_configurator) do
191
- file_other_db = ".other_db.standalone_migrations"
192
- File.open(file_other_db, "w") { |file| file.write(yaml_hash_other_db.to_yaml) }
193
214
  Configurator.new
194
215
  end
195
216
 
196
217
  it "look up named dot file" do
197
- expect(other_configurator.config).to eq(yaml_hash_other_db['config']['database'])
218
+ expect(other_configurator.c_os['paths']['config/database']).to(
219
+ eq(yaml_hash_other_db['config']['database'])
220
+ )
198
221
  end
199
222
 
200
223
  it "load config from named dot file" do
201
- expect(other_configurator.migrate_dir).to eq('db2/migrate')
224
+ expect(other_configurator.c_os['paths']['db/migrate']).to(
225
+ eq('db2/migrate')
226
+ )
202
227
  end
203
228
 
204
229
  after(:all) do
205
- File.delete ".other_db.standalone_migrations"
206
230
  ENV['DATABASE'] = nil
207
231
  end
208
232
 
@@ -222,38 +246,46 @@ module StandaloneMigrations
222
246
  end
223
247
 
224
248
  it "use default values for the missing configurations" do
225
- expect(configurator.migrate_dir).to eq('db/migrate')
249
+ expect(configurator.c_os['paths']['db']).to(
250
+ eq('db' )
251
+ )
252
+ expect(configurator.c_os['paths']['db/migrate']).to(
253
+ eq('db/migrate' )
254
+ )
226
255
  end
227
256
 
228
257
  it "use custom config from file" do
229
- expect(configurator.config).to eq(yaml_hash["config"]["database"])
258
+ expect(configurator.c_os['paths']['config/database']).to(
259
+ eq(yaml_hash["config"]["database"])
260
+ )
230
261
  end
231
262
 
232
263
  it "use custom config value from partial configuration" do
233
- expect(configurator.seeds).to eq(yaml_hash["db"]["seeds"])
264
+ expect(configurator.c_os['paths']['db/seeds.rb']).to(
265
+ eq(yaml_hash["db"]["seeds"])
266
+ )
234
267
  end
235
268
 
236
269
  end
237
270
 
238
271
  it "use custom config from file" do
239
- expect(configurator.config).to eq(yaml_hash["config"]["database"])
272
+ expect(configurator.c_os['paths']['config/database']).to(
273
+ eq(yaml_hash["config"]["database"])
274
+ )
240
275
  end
241
276
 
242
277
  it "use custom migrate dir from file" do
243
- expect(configurator.migrate_dir).to eq(yaml_hash["db"]["migrate"])
278
+ expect(configurator.c_os['paths']['db/migrate']).to eq(yaml_hash["db"]["migrate"])
244
279
  end
245
280
 
246
281
  it "use custom seeds from file" do
247
- expect(configurator.seeds).to eq(yaml_hash["db"]["seeds"])
282
+ expect(configurator.c_os['paths']['db/seeds.rb']).to eq(yaml_hash["db"]["seeds"])
248
283
  end
249
284
 
250
285
  it "use custom schema from file" do
251
- expect(configurator.schema).to eq(yaml_hash["db"]["schema"])
252
- end
253
-
254
- after(:all) do
255
- File.delete ".standalone_migrations"
256
- Dir.chdir @original_dir
286
+ expect(configurator.schema).to(
287
+ eq(yaml_hash["db"]["schema"])
288
+ )
257
289
  end
258
290
 
259
291
  end
@@ -3,36 +3,31 @@ describe 'Standalone migrations' do
3
3
 
4
4
  def write(file, content)
5
5
  raise "cannot write nil" unless file
6
- file = tmp_file(file)
7
6
  folder = File.dirname(file)
8
- `mkdir -p #{folder}` unless File.exist?(folder)
7
+ FileUtils.mkdir_p(folder) if folder != ''
9
8
  File.open(file, 'w') { |f| f.write content }
10
9
  end
11
10
 
12
11
  def read(file)
13
- File.read(tmp_file(file))
12
+ File.read(file)
14
13
  end
15
14
 
16
15
  def migration(name)
17
- m = `cd spec/tmp/db/migrate && ls`.split("\n").detect { |m| m =~ /#{name}/ }
16
+ m = `cd db/migrate && ls`.split("\n").detect { |m| m =~ /#{name}/ }
18
17
  m ? "db/migrate/#{m}" : m
19
18
  end
20
19
 
21
- def tmp_file(file)
22
- "spec/tmp/#{file}"
23
- end
24
-
25
20
  def schema
26
- ENV['SCHEMA']
21
+ ENV['SCHEMA'] || 'db/schema.rb'
27
22
  end
28
23
 
29
24
  def run(cmd)
30
- result = `cd spec/tmp && #{cmd} 2>&1`
25
+ result = `#{cmd} 2>&1`
31
26
  raise result unless $?.success?
32
27
  result
33
28
  end
34
29
 
35
- def make_migration(name, options={})
30
+ def make_migration(name, options = {})
36
31
  task_name = options[:task_name] || 'db:new_migration'
37
32
  migration = run("rake #{task_name} name=#{name}").match(%r{db/migrate/\d+.*.rb})[0]
38
33
  content = read(migration)
@@ -42,9 +37,9 @@ describe 'Standalone migrations' do
42
37
  migration.match(/\d{14}/)[0]
43
38
  end
44
39
 
45
- def write_rakefile(config=nil)
40
+ def write_rakefile(config = nil)
46
41
  write 'Rakefile', <<-TXT
47
- $LOAD_PATH.unshift '#{File.expand_path('lib')}'
42
+ $LOAD_PATH.unshift '#{File.expand_path('../../lib')}'
48
43
  begin
49
44
  require "standalone_migrations"
50
45
  StandaloneMigrations::Tasks.load_tasks
@@ -56,10 +51,10 @@ end
56
51
 
57
52
  def write_multiple_migrations
58
53
  migration_superclass = if Rails::VERSION::MAJOR >= 5
59
- "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
60
- else
61
- "ActiveRecord::Migration"
62
- end
54
+ "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
55
+ else
56
+ "ActiveRecord::Migration"
57
+ end
63
58
 
64
59
  write_rakefile %{t.migrations = "db/migrations", "db/migrations2"}
65
60
  write "db/migrate/20100509095815_create_tests.rb", <<-TXT
@@ -86,10 +81,17 @@ end
86
81
  TXT
87
82
  end
88
83
 
84
+ around(:each) do |example|
85
+ FileUtils.mkdir_p('tmp')
86
+ Dir.mktmpdir("spec-", "tmp") do |dir|
87
+ Dir.chdir(dir) do
88
+ example.run
89
+ end
90
+ end
91
+ end
92
+
89
93
  before do
90
94
  StandaloneMigrations::Configurator.instance_variable_set(:@env_config, nil)
91
- `rm -rf spec/tmp` if File.exist?('spec/tmp')
92
- `mkdir spec/tmp`
93
95
  write_rakefile
94
96
  write(schema, '')
95
97
  write 'db/config.yml', <<-TXT
@@ -105,10 +107,6 @@ production:
105
107
  TXT
106
108
  end
107
109
 
108
- after(:all) do
109
- `rm -rf spec/tmp` if File.exist?('spec/tmp')
110
- end
111
-
112
110
  it "warns of deprecated folder structure" do
113
111
  warning = /DEPRECATED.* db\/migrate/
114
112
  expect(run("rake db:create")).not_to match(warning)
@@ -135,16 +133,14 @@ production:
135
133
  expect(connection_established).to be true
136
134
  end
137
135
 
138
- Dir.chdir(File.join(File.dirname(__FILE__), "tmp")) do
139
- load "Rakefile"
140
- Rake::Task['standalone:connection'].invoke
141
- end
136
+ load "Rakefile"
137
+ Rake::Task['standalone:connection'].invoke
142
138
  end
143
139
  end
144
140
 
145
141
  describe 'db:new_migration' do
146
142
  it "fails if i do not add a name" do
147
- expect(lambda{ run("rake db:new_migration") }).to raise_error(/name=/)
143
+ expect { run("rake db:new_migration") }.to raise_error(/name=/)
148
144
  end
149
145
 
150
146
  it "generates a new migration with this name from ENV and timestamp" do
@@ -213,7 +209,7 @@ production:
213
209
  make_migration('yyy')
214
210
  # Rails has a bug where it's sending a bad failure exception
215
211
  # https://github.com/rails/rails/issues/28905
216
- expect(lambda{ run("rake db:migrate:down") }).to raise_error(/VERSION|version/)
212
+ expect { run("rake db:migrate:down") }.to raise_error(/VERSION|version/)
217
213
  end
218
214
  end
219
215
 
@@ -232,7 +228,7 @@ production:
232
228
  make_migration('yyy')
233
229
  # Rails has a bug where it's sending a bad failure exception
234
230
  # https://github.com/rails/rails/issues/28905
235
- expect(lambda{ run("rake db:migrate:up") }).to raise_error(/VERSION|version/)
231
+ expect { run("rake db:migrate:up") }.to raise_error(/VERSION|version/)
236
232
  end
237
233
  end
238
234
 
@@ -271,7 +267,7 @@ production:
271
267
  describe 'db:schema:load' do
272
268
  it "loads the schema" do
273
269
  run('rake db:schema:dump')
274
- write(schema, read(schema)+"\nputs 'LOADEDDD'")
270
+ write(schema, read(schema) + "\nputs 'LOADEDDD'")
275
271
  result = run('rake db:schema:load')
276
272
  expect(result).to match(/LOADEDDD/)
277
273
  end
@@ -282,7 +278,7 @@ production:
282
278
  run "rake db:drop"
283
279
  run "rake db:create"
284
280
  run "rake db:schema:load"
285
- expect(run( "rake db:migrate").strip).to eq('')
281
+ expect(run("rake db:migrate").strip).to eq('')
286
282
  end
287
283
  end
288
284
 
@@ -293,20 +289,20 @@ production:
293
289
 
294
290
  it "fails when migrations are pending" do
295
291
  make_migration('yyy')
296
- expect(lambda{ run("rake db:abort_if_pending_migrations") }).to raise_error(/1 pending migration/)
292
+ expect { run("rake db:abort_if_pending_migrations") }.to raise_error(/1 pending migration/)
297
293
  end
298
294
  end
299
295
 
300
296
  describe 'db:test:load' do
301
297
  it 'loads' do
302
298
  write(schema, "puts 'LOADEDDD'")
303
- expect(run("rake db:test:load")).to match(/LOADEDDD/)
299
+ expect(run("rake db:test:load_schema")).to match(/LOADEDDD/)
304
300
  end
305
301
 
306
302
  it "fails without schema" do
307
- schema_path = "spec/tmp/#{schema}"
303
+ schema_path = schema
308
304
  `rm -rf #{schema_path}` if File.exist?(schema_path)
309
- expect(lambda{ run("rake db:test:load") }).to raise_error(/try again/)
305
+ expect { run("rake db:test:load_schema") }.to raise_error(/try again/)
310
306
  end
311
307
  end
312
308
 
@@ -335,14 +331,12 @@ production:
335
331
  write(".standalone_migrations", yaml_hash.to_yaml)
336
332
  end
337
333
 
338
-
339
334
  it "loads" do
340
335
  write("db/seeds2.rb", "puts 'LOADEDDD'")
341
336
  expect(run("rake db:seed")).to match(/LOADEDDD/)
342
337
  end
343
338
  end
344
339
 
345
-
346
340
  it "does nothing without seeds" do
347
341
  expect(run("rake db:seed").length).to eq(0)
348
342
  end
@@ -352,7 +346,7 @@ production:
352
346
  it "should not error when a seeds file does not exist" do
353
347
  make_migration('yyy')
354
348
  run('rake db:migrate DB=test')
355
- expect(lambda{ run("rake db:reset") }).not_to raise_error
349
+ expect { run("rake db:reset") }.not_to raise_error
356
350
  end
357
351
  end
358
352
 
@@ -365,7 +359,7 @@ production:
365
359
  end
366
360
 
367
361
  it "should error on an invalid database", :travis_error => true do
368
- expect(lambda{ run("rake db:create RAILS_ENV=nonexistent")}).to raise_error(/rake aborted/)
362
+ expect { run("rake db:create RAILS_ENV=nonexistent") }.to raise_error(/rake aborted/)
369
363
  end
370
364
  end
371
365
  end
@@ -2,33 +2,39 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: standalone_migrations 7.1.1 ruby lib
5
+ # stub: standalone_migrations 7.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "standalone_migrations".freeze
9
- s.version = "7.1.1"
9
+ s.version = "7.1.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Todd Huss".freeze, "Michael Grosser".freeze]
14
- s.date = "2023-04-06"
14
+ s.date = "2023-11-17"
15
15
  s.email = "thuss@gabrito.com".freeze
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
18
  "README.markdown"
19
19
  ]
20
20
  s.files = [
21
+ ".github/workflows/CI.yml",
21
22
  ".rspec",
22
- ".travis.yml",
23
23
  "Gemfile",
24
24
  "LICENSE",
25
25
  "README.markdown",
26
26
  "Rakefile",
27
27
  "VERSION",
28
- "example/.gitignore",
28
+ "example/Gemfile",
29
+ "example/README.markdown",
29
30
  "example/Rakefile",
31
+ "example/app/models/movie.rb",
32
+ "example/article.pdf",
33
+ "example/boot.rb",
34
+ "example/db/.gitignore",
30
35
  "example/db/config.yml",
31
- "example/db/migrate/20120930053225_create_table_awesome_migration.rb",
36
+ "example/db/migrate/20210202023614_create_movies.rb",
37
+ "example/db/schema.rb",
32
38
  "lib/standalone_migrations.rb",
33
39
  "lib/standalone_migrations/callbacks.rb",
34
40
  "lib/standalone_migrations/configurator.rb",
@@ -60,12 +66,14 @@ Gem::Specification.new do |s|
60
66
 
61
67
  if s.respond_to? :add_runtime_dependency then
62
68
  s.add_runtime_dependency(%q<rake>.freeze, [">= 10.0"])
63
- s.add_runtime_dependency(%q<activerecord>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
64
- s.add_runtime_dependency(%q<railties>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
69
+ s.add_runtime_dependency(%q<activerecord>.freeze, [">= 6.0.0", "< 7.2"])
70
+ s.add_runtime_dependency(%q<railties>.freeze, [">= 6.0.0", "< 7.2"])
71
+ s.add_runtime_dependency(%q<nokogiri>.freeze, ["~> 1.14"])
65
72
  else
66
73
  s.add_dependency(%q<rake>.freeze, [">= 10.0"])
67
- s.add_dependency(%q<activerecord>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
68
- s.add_dependency(%q<railties>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
74
+ s.add_dependency(%q<activerecord>.freeze, [">= 6.0.0", "< 7.2"])
75
+ s.add_dependency(%q<railties>.freeze, [">= 6.0.0", "< 7.2"])
76
+ s.add_dependency(%q<nokogiri>.freeze, ["~> 1.14"])
69
77
  end
70
78
  end
71
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standalone_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 7.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Huss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-06 00:00:00.000000000 Z
12
+ date: 2023-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -31,64 +31,54 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 4.2.7
34
+ version: 6.0.0
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
- version: 7.1.0
38
- - - "!="
39
- - !ruby/object:Gem::Version
40
- version: 5.2.3
41
- - - "!="
42
- - !ruby/object:Gem::Version
43
- version: 5.2.3.rc1
37
+ version: '7.2'
44
38
  type: :runtime
45
39
  prerelease: false
46
40
  version_requirements: !ruby/object:Gem::Requirement
47
41
  requirements:
48
42
  - - ">="
49
43
  - !ruby/object:Gem::Version
50
- version: 4.2.7
44
+ version: 6.0.0
51
45
  - - "<"
52
46
  - !ruby/object:Gem::Version
53
- version: 7.1.0
54
- - - "!="
55
- - !ruby/object:Gem::Version
56
- version: 5.2.3
57
- - - "!="
58
- - !ruby/object:Gem::Version
59
- version: 5.2.3.rc1
47
+ version: '7.2'
60
48
  - !ruby/object:Gem::Dependency
61
49
  name: railties
62
50
  requirement: !ruby/object:Gem::Requirement
63
51
  requirements:
64
52
  - - ">="
65
53
  - !ruby/object:Gem::Version
66
- version: 4.2.7
54
+ version: 6.0.0
67
55
  - - "<"
68
56
  - !ruby/object:Gem::Version
69
- version: 7.1.0
70
- - - "!="
71
- - !ruby/object:Gem::Version
72
- version: 5.2.3
73
- - - "!="
74
- - !ruby/object:Gem::Version
75
- version: 5.2.3.rc1
57
+ version: '7.2'
76
58
  type: :runtime
77
59
  prerelease: false
78
60
  version_requirements: !ruby/object:Gem::Requirement
79
61
  requirements:
80
62
  - - ">="
81
63
  - !ruby/object:Gem::Version
82
- version: 4.2.7
64
+ version: 6.0.0
83
65
  - - "<"
84
66
  - !ruby/object:Gem::Version
85
- version: 7.1.0
86
- - - "!="
67
+ version: '7.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: nokogiri
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
87
73
  - !ruby/object:Gem::Version
88
- version: 5.2.3
89
- - - "!="
74
+ version: '1.14'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
90
80
  - !ruby/object:Gem::Version
91
- version: 5.2.3.rc1
81
+ version: '1.14'
92
82
  description:
93
83
  email: thuss@gabrito.com
94
84
  executables: []
@@ -97,17 +87,23 @@ extra_rdoc_files:
97
87
  - LICENSE
98
88
  - README.markdown
99
89
  files:
90
+ - ".github/workflows/CI.yml"
100
91
  - ".rspec"
101
- - ".travis.yml"
102
92
  - Gemfile
103
93
  - LICENSE
104
94
  - README.markdown
105
95
  - Rakefile
106
96
  - VERSION
107
- - example/.gitignore
97
+ - example/Gemfile
98
+ - example/README.markdown
108
99
  - example/Rakefile
100
+ - example/app/models/movie.rb
101
+ - example/article.pdf
102
+ - example/boot.rb
103
+ - example/db/.gitignore
109
104
  - example/db/config.yml
110
- - example/db/migrate/20120930053225_create_table_awesome_migration.rb
105
+ - example/db/migrate/20210202023614_create_movies.rb
106
+ - example/db/schema.rb
111
107
  - lib/standalone_migrations.rb
112
108
  - lib/standalone_migrations/callbacks.rb
113
109
  - lib/standalone_migrations/configurator.rb
data/.travis.yml DELETED
@@ -1,29 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5.9
4
- - 2.6.9
5
- - 2.7.5
6
- - 3.0.3
7
- env:
8
- - AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
9
- - AR="~> 5.0.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
10
- - AR=">= 5.1.0.rc2,< 5.2" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
11
- - AR=">= 5.2.0.rc2,< 5.3,!= 5.2.3,!=5.2.3.rc1" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
12
- - AR="~> 6.0.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
13
- - AR="~> 6.1.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
14
- - AR="~> 7.0.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
15
- jobs:
16
- exclude:
17
- - rvm: 2.6.9
18
- env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
19
- - rvm: 2.7.5
20
- env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
21
- - rvm: 3.0.3
22
- env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
23
- - rvm: 2.7.5
24
- env: AR="~> 5.0.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
25
- - rvm: 2.7.5
26
- env: AR=">= 5.1.0.rc2,< 5.2" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
27
- - rvm: 2.7.5
28
- env: AR=">= 5.2.0.rc2,< 5.3,!= 5.2.3,!=5.2.3.rc1" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
29
- script: bundle exec rake specs:travis
data/example/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sqlite3
2
- Gemfile
3
- .bundle/
4
- bin/
5
- Gemfile.lock
@@ -1,7 +0,0 @@
1
- class CreateTableAwesomeMigration < ActiveRecord::Migration[5.0]
2
- def up
3
- end
4
-
5
- def down
6
- end
7
- end