wanderung 0.2.0 → 0.3.0

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: 4a367aa9991fc7958890eec4d78193f0c20380edff9940a697113034fe1871a7
4
- data.tar.gz: 6bb0ab17974db3bc4f3bb80761d9abe61b12f032579e9141d9bbf8bf8d8de8df
3
+ metadata.gz: c50050f423109944ef2d38ef50113f028fc1aa5f47a40c1bc0ec3424e99055f8
4
+ data.tar.gz: 8304f2f0ed3db7900be692b76c35300d7bd2f763f02f9312f9e97c5ea09fedd1
5
5
  SHA512:
6
- metadata.gz: 919d6a0b5ef042bdee29e7a7f4b2ede8146459c781729fea5ce8331c04928c30472f25acd745997cb6bd63bbdce02ece8fa47561ca89d3a3f0a9128eeb8b37f7
7
- data.tar.gz: 2503de79ca6ff2691d26b51bd546462529a6ab1fe82fb1a686cfb1989e284f48dcd191b41077cfc64bef52d8261c21ffcdbf5f349b3765e6e8b9ef27200e171b
6
+ metadata.gz: 72e2ffc2214accf4564c071bda133803e775ac0815b9ae72f31ff2be37861ecf158c15716b3d25a1bc888bc863f8443081bb10c5038ed9a360444404e511f3f9
7
+ data.tar.gz: 81d67dd10f11c6a7356d8238a429fe412b82269467cfad54efd9298dd775418e3e766dd77339990ee44257c14dcd7151c2a259c42aded66477af14541d9174c3
@@ -15,6 +15,7 @@ jobs:
15
15
  ruby-version: 2.6.3
16
16
  - name: Build and test with Rake
17
17
  run: |
18
+ sudo apt-get install libsqlite3-dev
18
19
  gem install bundler
19
20
  bundle install --jobs 4 --retry 3
20
21
  bundle exec rake
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ test/*.db
11
+ *.db
data/CHANGELOG.md CHANGED
@@ -5,3 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+
9
+ ## [0.3.0] - 2019-10-01
10
+
11
+ ### Added
12
+
13
+ - Capabilities to run multiple migrations
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wanderung (0.1.0)
4
+ wanderung (0.2.0)
5
+ sequel (~> 5.25)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -25,6 +26,8 @@ GEM
25
26
  ruby-progressbar (~> 1.7)
26
27
  unicode-display_width (>= 1.4.0, < 1.7)
27
28
  ruby-progressbar (1.10.1)
29
+ sequel (5.25.0)
30
+ sqlite3 (1.4.1)
28
31
  thor (0.20.3)
29
32
  unicode-display_width (1.6.0)
30
33
 
@@ -37,6 +40,7 @@ DEPENDENCIES
37
40
  minitest (~> 5.0)
38
41
  rake (~> 10.0)
39
42
  rubocop (= 0.75.0)
43
+ sqlite3 (~> 1.4)
40
44
  wanderung!
41
45
 
42
46
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Wanderung
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wanderung`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Wanderung helps you to manage multiple migrations within the same repository
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ It uses [Sequel](https://github.com/jeremyevans/sequel) internally to manage the migrations. Therefore, the same syntax is expected
6
+
7
+ ## Motivation
8
+
9
+ As part of a project that we were working on, we had to orchestrate multiple databases, whenever these started to grow,
10
+ it became troublesome to have to run several migrations for the micro-services to work together properly.
11
+
12
+ We wanted to have all of our migrations in a single place, run a single command and have them all executed.
6
13
 
7
14
  ## Installation
8
15
 
@@ -22,7 +29,31 @@ Or install it yourself as:
22
29
 
23
30
  ## Usage
24
31
 
25
- TODO: Write usage instructions here
32
+ ```ruby
33
+ # Simple Migration
34
+ Wanderung.new(
35
+ database: 'artists', connection_uri: 'sqlite://artists.db'
36
+ ).run
37
+
38
+ # Path of the folder where the migrations are is assumed from the db name, but it can also be specified
39
+
40
+ Wanderung.new(
41
+ database: 'artists', connection_uri: 'sqlite://artists.db', path: 'my_migrations/artists'
42
+ ).run
43
+
44
+ # Multiple databases can also be passed in as an array
45
+ Wanderung.new(
46
+ { database: 'artists', connection_uri: 'sqlite://artists.db', path: 'my_migrations/artists' },
47
+ { database: 'not_artists', connection_uri: 'sqlite://not_artists.db' }
48
+ ).run
49
+
50
+ # A logger can be supplied so that the migrations are logged
51
+ Wanderung.new(database: 'artists', connection_uri: 'sqlite://artists.db').tap { |w| w.logger = Logger.new(STDOUT) }.run
52
+ ```
53
+
54
+ It supports all of the [adapters that Sequel supports](https://github.com/jeremyevans/sequel#sequel-the-database-toolkit-for-ruby)
55
+
56
+ A simple example can be found in the test folder
26
57
 
27
58
  ## Development
28
59
 
@@ -32,4 +63,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
63
 
33
64
  ## Contributing
34
65
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wanderung.
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/belfazt/wanderung.
data/lib/wanderung.rb CHANGED
@@ -1,8 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'wanderung/version'
4
+ require 'wanderung/database'
4
5
 
5
- module Wanderung
6
- class Error < StandardError; end
7
- # Your code goes here...
6
+ require 'sequel'
7
+
8
+ ##
9
+ # Allows you to create multiple database schemas
10
+ class Wanderung
11
+ def initialize(database_configs)
12
+ @database_configs = database_configs.is_a?(Hash) ? [database_configs] : database_configs
13
+ end
14
+
15
+ def run
16
+ databases.map(&:migrate)
17
+ end
18
+
19
+ attr_writer :logger
20
+
21
+ private
22
+
23
+ def databases
24
+ @databases ||= @database_configs.map do |database_config|
25
+ path = database_config.fetch(:path, database_config.fetch(:database))
26
+ Database.new(
27
+ path: [Dir.pwd, path].join('/'),
28
+ connection_uri: database_config.fetch(:connection_uri),
29
+ logger: @logger
30
+ )
31
+ end
32
+ end
8
33
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
5
+ class Wanderung
6
+ ##
7
+ # Object to represent a database, with its migration counterpart
8
+ class Database
9
+ Sequel.extension :migration
10
+ def initialize(connection_uri:, path:, logger:)
11
+ @logger = logger
12
+ @db = Sequel.connect(connection_uri).tap { |db| db.logger = logger }.freeze
13
+ @path = path
14
+ end
15
+
16
+ def migrate
17
+ Sequel::Migrator.run(@db, @path)
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Wanderung
4
- VERSION = '0.2.0'
3
+ class Wanderung
4
+ VERSION = '0.3.0'
5
5
  end
data/wanderung.gemspec CHANGED
@@ -31,4 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'minitest', '~> 5.0'
32
32
  spec.add_development_dependency 'rake', '~> 10.0'
33
33
  spec.add_development_dependency 'rubocop', '0.75.0'
34
+ spec.add_development_dependency 'sqlite3', '~> 1.4'
35
+
36
+ spec.add_runtime_dependency 'sequel', '~> 5.25'
34
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wanderung
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Camargo
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.75.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sequel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.25'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.25'
83
111
  description:
84
112
  email:
85
113
  - dicamargov@gmail.com
@@ -100,6 +128,7 @@ files:
100
128
  - bin/console
101
129
  - bin/setup
102
130
  - lib/wanderung.rb
131
+ - lib/wanderung/database.rb
103
132
  - lib/wanderung/version.rb
104
133
  - wanderung.gemspec
105
134
  homepage: https://github.com/belfazt/wanderung