migrate 0.0.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 57dbdb10510d769127eb53e1ff5edc510d76804a
4
- data.tar.gz: 28a067bb33de00846919a752d0c9ceede0a0ee3c
2
+ SHA256:
3
+ metadata.gz: '068edcb37106f1848382dbe09a797743785b6ce15a3f3fd774b0026e272cd967'
4
+ data.tar.gz: 179111bfdcb3a20bd0f051eca9d8ddf0766fb5e11971e118d441ffd6db33dce1
5
5
  SHA512:
6
- metadata.gz: b33b5189678be5ef524b0f9073f53ec4e3b8a15fca9336f67e502726e6a889f3884c3748f75589a9daf3c03df462f0aa797a6748b6b3acef6c0568092d8a4b63
7
- data.tar.gz: 1d76ce821d9c4986fdff128bdaae288d68a868fd96f12c059e5ac805ca4c44f6290229008168c207538e60cf51b7ee4f9b929500307750619efa98d64ff4cb33
6
+ metadata.gz: fbfd24c35f7405d2b182a77edfb5e66fe9f543738b4b64b76c39ae0e064d6bc83768f004bed53ba112ea4f251332d370587a2a6caa951e2f4f5b2cae42be4bb3
7
+ data.tar.gz: 7ba48b03e573813efe4e88f34c13c333a385890b38a938100c1f624e838fd349ffd2d43ce56e9d13fdfb2e3787e5d0e0d0dad1e46f34e9911d3f244564a70aa7
@@ -18,52 +18,38 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require 'console'
22
+ require 'build/files'
23
+
24
+ require_relative 'migration'
25
+
21
26
  module Migrate
22
27
  class Controller
23
- def initialize
24
- @migrations = {}
25
- end
28
+ ROOT = Build::Files::Path.current / "migrate"
26
29
 
27
- attr :migrations
28
-
29
- # Apply the given migration.
30
- def apply(migration)
31
- start_time = Time.now
32
-
33
- yield
34
-
35
- duration = Time.now - start_time
36
-
37
- commit(migration)
30
+ def initialize(root = ROOT)
31
+ @root = root
38
32
  end
39
33
 
40
- # Persist that the migration was applied.
41
- def commit(migration)
42
- @migrations[migration.name] = migration
34
+ def migrations
35
+ @root.glob("**/*.rb").map{|path| Migration.new(path)}.sort
43
36
  end
44
37
 
45
- def << migrations
38
+ def migrate!
46
39
  migrations.each do |migration|
47
- apply(migration) do
48
- migration.call(self)
49
- end unless @migrations.include?(migration)
40
+ Console.logger.debug(self, "Applying #{migration}...")
41
+ migration.call(self)
50
42
  end
51
43
  end
52
- end
53
-
54
- class FileController
55
- def initialize(root)
56
- @root = root
57
-
58
- super()
59
- end
60
44
 
61
- def migrations
62
- @migrations ||= load_migrations
63
- end
64
-
65
- def load_migrations
45
+ def create!(name, &block)
46
+ prefix = Time.now.strftime("%Y%m%d%H%M%S")
47
+ path = @root / "#{prefix}-#{name}.rb"
48
+ path.parent.mkpath
49
+
50
+ path.open(File::CREAT|File::TRUNC|File::WRONLY, &block)
66
51
 
52
+ return path
67
53
  end
68
54
  end
69
55
  end
@@ -20,30 +20,27 @@
20
20
 
21
21
  module Migrate
22
22
  class Migration
23
- def self.migration_name
24
- self.name
25
- end
26
-
27
- def initialize(name = self.class.migration_name)
28
- @name = name
23
+ def initialize(path)
24
+ @path = path
25
+ @name = path.relative_path
29
26
  end
30
27
 
31
28
  attr :name
32
29
 
33
30
  def call(controller)
31
+ self.instance_eval(::File.read(@path), @path)
32
+ end
33
+
34
+ def migrate(target, using:, &block)
35
+ using.migrate(self.name, target, &block)
36
+ end
37
+
38
+ def to_s
39
+ @name
34
40
  end
35
41
 
36
- def self.load_path(path)
37
- klass = Class.new(Migration)
38
- migration_name = File.basename(path)
39
-
40
- klass.define_singleton_method(:migration_name) do
41
- migration_name
42
- end
43
-
44
- klass.class_eval(File.read(path), path)
45
-
46
- klass.freeze
42
+ def <=> other
43
+ @name <=> other.name
47
44
  end
48
45
  end
49
46
  end
@@ -0,0 +1,28 @@
1
+ using.migrate(self.name, target, &block)
2
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ module Migrate
23
+ class Provider
24
+ def migrate(migration, target, &block)
25
+ yield
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Migrate
3
- VERSION = "0.0.0"
3
+ VERSION = "0.3.0"
4
4
  end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: build-files
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
20
- type: :development
19
+ version: '1.7'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,28 +66,23 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
- description:
69
+ description:
56
70
  email:
57
- - samuel.williams@oriontransfer.co.nz
58
71
  executables: []
59
72
  extensions: []
60
73
  extra_rdoc_files: []
61
74
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
- - Gemfile
66
- - README.md
67
- - Rakefile
68
75
  - lib/migrate.rb
69
76
  - lib/migrate/controller.rb
70
77
  - lib/migrate/migration.rb
78
+ - lib/migrate/provider.rb
71
79
  - lib/migrate/version.rb
72
- - migrate.gemspec
73
- homepage: https://github.com/ioquatix/migrate
74
- licenses: []
75
- metadata: {}
76
- post_install_message:
80
+ homepage: https://github.com/socketry/migrate
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ funding_uri: https://github.com/sponsors/ioquatix/
85
+ post_install_message:
77
86
  rdoc_options: []
78
87
  require_paths:
79
88
  - lib
@@ -88,9 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
97
  - !ruby/object:Gem::Version
89
98
  version: '0'
90
99
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.6.11
93
- signing_key:
100
+ rubygems_version: 3.2.3
101
+ signing_key:
94
102
  specification_version: 4
95
103
  summary: Generic library to support migrations.
96
104
  test_files: []
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,5 +0,0 @@
1
- --color
2
- --format documentation
3
- --backtrace
4
- --require spec_helper
5
- --warnings
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.14.6
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in migrate.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem "build-files"
8
- end
data/README.md DELETED
@@ -1,55 +0,0 @@
1
- # Migrate
2
-
3
- Provides a generic set of tools to implement migrations.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'migrate'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install migrate
20
-
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
-
25
- ## Contributing
26
-
27
- 1. Fork it
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create new Pull Request
32
-
33
- ## License
34
-
35
- Released under the MIT license.
36
-
37
- Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
38
-
39
- Permission is hereby granted, free of charge, to any person obtaining a copy
40
- of this software and associated documentation files (the "Software"), to deal
41
- in the Software without restriction, including without limitation the rights
42
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
- copies of the Software, and to permit persons to whom the Software is
44
- furnished to do so, subject to the following conditions:
45
-
46
- The above copyright notice and this permission notice shall be included in
47
- all copies or substantial portions of the Software.
48
-
49
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
55
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/migrate.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'lib/migrate/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "migrate"
6
- spec.version = Migrate::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
-
10
- spec.summary = "Generic library to support migrations."
11
- spec.homepage = "https://github.com/ioquatix/migrate"
12
-
13
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
- f.match(%r{^(test|spec|features)/})
15
- end
16
- spec.bindir = "bin"
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_development_dependency "bundler", "~> 1.14"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec", "~> 3.0"
23
- end