departure 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dccdd8a6c5b4d999a33190da99a256a3137354f0
4
+ data.tar.gz: 2664666f2e7495b7c911ae318fd353063563e89e
5
+ SHA512:
6
+ metadata.gz: fb1e87a5c4fc141b9d67959dedebc20403bdce9d79aa428d4e85a7ffb49498097429e6699fd9f900ff86b0d1b8827a141ba39440324937c44ffd4b45a860d5ce
7
+ data.tar.gz: 81b27761f2f7e72f5a10c631caac8587fa379790934683b5d7d439e4756bbfa9dec5d4170a7b494e778df832e3717514d46682fec5554ba019f8b3d8d28daac3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ tags
12
+ percona_migrator_error.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install:
5
+ - sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5
6
+ - echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list
7
+ - sudo apt-get update -qq
8
+ - sudo apt-get install percona-toolkit
9
+ - gem update bundler
10
+ - bin/setup
11
+ after_success:
12
+ - codeclimate-test-reporter
13
+
14
+ branches:
15
+ only:
16
+ - master
@@ -0,0 +1,95 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+ ### Changed
11
+ ### Removed
12
+ ### Fixed
13
+
14
+ ## [0.1.1] - 2017-03-10
15
+
16
+ ### Added
17
+
18
+ - Store pt-online-schema-change's stderr to percona_migrator_error.log in the
19
+ default Rails tmp folder.
20
+ - Allow configuring the tmp directory where the error log gets written into.
21
+ - Output a deprecation warning when installing and running the gem. It will be
22
+ replaced by Departure soon.
23
+
24
+ ### Changed
25
+
26
+ - No longer a hard dependency on mysql2 0.3.20. Will accept 0.3.20 or any
27
+ higher patch revisions.
28
+
29
+ ### Fixed
30
+
31
+ - Output pt-online-schema-change's stdout while the migration is running instead
32
+ of all of it at the end.
33
+
34
+ ## [0.1.0.rc.7] - 2016-09-15
35
+
36
+ ### Added
37
+
38
+ - Toggle pt-online-schema-change's output as well when toggling the migration's
39
+ verbose option.
40
+
41
+ ### Changed
42
+
43
+ - Enabled pt-online-schema-change's output while running the migration, that got
44
+ broken in v0.1.0.rc.2
45
+
46
+ ## [0.1.0.rc.6] - 2016-04-07
47
+
48
+ ### Added
49
+
50
+ - Support non-ddl migrations by implementing the methods for the ActiveRecord
51
+ quering to work.
52
+
53
+ ### Changed
54
+
55
+ - Refactor the PerconaAdapter to use the Runner as connection client, as all the
56
+ other adapters.
57
+
58
+ ## [0.1.0.rc.5] - 2016-03-29
59
+
60
+ ### Changed
61
+
62
+ - Raise a ActiveRecord::StatementInvalid on failed migration. It also provides
63
+ more detailed error message when possible such as pt-onlin-schema-change
64
+ being missing.
65
+
66
+ ## [0.1.0.rc.4] - 2016-03-15
67
+
68
+ ### Added
69
+
70
+ - Support #drop_table
71
+ - Support for foreing keys in db/schema.rb when using [Foreigner
72
+ gem](https://github.com/matthuhiggins/foreigner) in Rails 3 apps. This allows to
73
+ define foreign keys with #execute, but does not provide support for
74
+ add_foreign_key yet.
75
+
76
+ ## [0.1.0.rc.3] - 2016-03-10
77
+
78
+ ### Added
79
+
80
+ - Support #execute. Allows to execute raw SQL from the migration
81
+
82
+ ## [0.1.0.rc.2] - 2016-03-09
83
+
84
+ ### Added
85
+
86
+ - VERBOSE env var in tests. Specially useful for integration tests.
87
+ - Fix #create_table migration method. Now it does create the table.
88
+
89
+ ### Changed
90
+
91
+ - Use ActiveRecord's logger instead of specifying one in the connection data.
92
+
93
+ ## [0.1.0.rc.1] - 2016-03-01
94
+
95
+ - Initial gem version
@@ -0,0 +1,50 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This Code of Conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at accounts@redbooth.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+
45
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
46
+ version 1.3.0, available at
47
+ [http://contributor-covenant.org/version/1/3/0/][version]
48
+
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "codeclimate-test-reporter", '~> 1.0.3', group: :test, require: nil
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Pau Pérez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,147 @@
1
+ # Departure [![Build Status](https://travis-ci.org/redbooth/departure.svg?branch=master)](https://travis-ci.org/redbooth/percona_migrator) [![Code Climate](https://codeclimate.com/github/redbooth/percona_migrator/badges/gpa.svg)](https://codeclimate.com/github/redbooth/percona_migrator)
2
+
3
+ Departure is an **ActiveRecord connection adapter** that allows running
4
+ **MySQL online and non-blocking DDL** through `ActiveRecord::Migration` without needing
5
+ to use a different DSL other than Rails' migrations DSL.
6
+
7
+ It uses `pt-online-schema-change` command-line tool of
8
+ [Percona
9
+ Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
10
+ which runs MySQL alter table statements without downtime.
11
+
12
+ ## Rename from "Percona Migrator"
13
+
14
+ This project was formerly known as "Percona Migrator", but this incurs in an
15
+ infringement of Percona's trade mark policy and thus has to be renamed. Said
16
+ name is likely to cause confusion as to the source of the wrapper.
17
+
18
+ The next major versions will use "Departure" as gem name.
19
+
20
+ ## Installation
21
+
22
+ Departure relies on `pt-online-schema-change` from [Percona
23
+ Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
24
+
25
+ ### Mac
26
+
27
+ `brew install percona-toolkit`
28
+
29
+ ### Linux
30
+
31
+ #### Ubuntu/Debian based
32
+
33
+ `apt-get install percona-toolkit`
34
+
35
+ #### Arch Linux
36
+
37
+ `pacman -S percona-toolkit perl-dbd-mysql`
38
+
39
+ #### Other distros
40
+
41
+ For other Linux distributions check out the [Percona Toolkit download
42
+ page](https://www.percona.com/downloads/percona-toolkit/) to find the package
43
+ that fits your distribution.
44
+
45
+ You can also get it from [Percona's apt repository](https://www.percona.com/doc/percona-xtradb-cluster/5.5/installation/apt_repo.html)
46
+
47
+ Once installed, add this line to your application's Gemfile:
48
+
49
+ ```ruby
50
+ gem 'percona_migrator'
51
+ ```
52
+
53
+ And then execute:
54
+
55
+ $ bundle
56
+
57
+ Or install it yourself as:
58
+
59
+ $ gem install percona_migrator
60
+
61
+ ## Usage
62
+
63
+ Once you added it to your app's Gemfile, you can create and run Rails migrations
64
+ as usual.
65
+
66
+ All the `ALTER TABLE` statements will be executed with
67
+ `pt-online-schema-change`, which will provide additional output to the
68
+ migration.
69
+
70
+ ### LHM support
71
+
72
+ If you moved to Soundcloud's [Lhm](https://github.com/soundcloud/lhm) already,
73
+ we got you covered. Departure overrides Lhm's DSL so that all the alter
74
+ statements also go through `pt-online-schema-change` as well.
75
+
76
+ You can keep your Lhm migrations and start using Rails migration's DSL back
77
+ again in your next migration.
78
+
79
+ ## Configuration
80
+
81
+ You can override any of the default values from an initializer:
82
+
83
+ ```ruby
84
+ PerconaMigrator.configure do |config|
85
+ config.tmp_path = '/tmp/'
86
+ end
87
+ ```
88
+
89
+ It's strongly recommended to name it after this gems name, such as
90
+ `config/initializers/percona_migrator.rb`
91
+
92
+ ## How it works
93
+
94
+ When booting your Rails app, Departure extends the
95
+ `ActiveRecord::Migration#migrate` method to reset the connection and reestablish
96
+ it using the `PerconaAdapter` instead of the one you defined in your
97
+ `config/database.yml`.
98
+
99
+ Then, when any migration DSL methods such as `add_column` or `create_table` are
100
+ executed, they all go to the
101
+ [PerconaAdapter](https://github.com/redbooth/percona_migrator/blob/master/lib/active_record/connection_adapters/percona_adapter.rb).
102
+ There, the methods that require `ALTER TABLE` SQL statements, like `add_column`,
103
+ are overriden to get executed with
104
+ [PerconaMigrator::Runner](https://github.com/redbooth/percona_migrator/blob/master/lib/percona_migrator/runner.rb),
105
+ which deals with the `pt-online-schema-change` binary. All the others, like
106
+ `create_table`, are delegated to the ActiveRecord's built in Mysql2Adapter and
107
+ so they follow the regular path.
108
+
109
+ [PerconaMigrator::Runner](https://github.com/redbooth/percona_migrator/blob/master/lib/percona_migrator/runner.rb)
110
+ spawns a new process that runs the `pt-online-schema-change` binary present in
111
+ the system, with the apropriate arguments for the generated SQL.
112
+
113
+ When an any error occurs, an `ActiveRecord::StatementInvalid` exception is
114
+ raised and the migration is aborted, as all other ActiveRecord connection
115
+ adapters.
116
+
117
+ ## Development
118
+
119
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
120
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
121
+ prompt that will allow you to experiment.
122
+
123
+ To install this gem onto your local machine, run `bundle exec rake install`. To
124
+ release a new version, update the version number in `version.rb`, and then run
125
+ `bundle exec rake release`, which will create a git tag for the version, push
126
+ git commits and tags, and push the `.gem` file to
127
+ [rubygems.org](https://rubygems.org).
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at
132
+ https://github.com/redbooth/percona_migrator.
133
+
134
+ Please note that this project is released with a Contributor Code of Conduct. By
135
+ participating in this project you agree to abide by its terms.
136
+
137
+ Check the code of conduct [here](CODE_OF_CONDUCT.md)
138
+
139
+ ## Changelog
140
+
141
+ You can consult the changelog [here](CHANGELOG.md)
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT
146
+ License](http://opensource.org/licenses/MIT).
147
+
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ require './configuration'
5
+ require './test_database'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+
11
+ namespace :db do
12
+ desc 'Create the test database'
13
+ task :create do
14
+ config = Configuration.new
15
+ TestDatabase.new(config).setup_test_database
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "percona_migrator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ bundle exec rake db:create
@@ -0,0 +1,3 @@
1
+ username: 'root'
2
+ password: ''
3
+ database: 'percona_migrator_test'
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ class Configuration
4
+ CONFIG_PATH = 'config.yml'
5
+
6
+ attr_reader :config
7
+
8
+ def initialize
9
+ @config = YAML.load_file(CONFIG_PATH)
10
+ end
11
+
12
+ def [](key)
13
+ config[key]
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'departure/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'departure'
9
+ spec.version = Departure::VERSION
10
+ spec.authors = ['Ilya Zayats', 'Pau Pérez', 'Fran Casas', 'Jorge Morante']
11
+ spec.email = ['ilya.zayats@redbooth.com', 'pau.perez@redbooth.com', 'fran.casas@redbooth.com', 'jorge.morante@redbooth.com']
12
+
13
+ spec.summary = %q{pt-online-schema-change runner for ActiveRecord migrations}
14
+ spec.description = %q{Execute your ActiveRecord migrations with Percona's pt-online-schema-change. Formerly known as Percona Migrator.}
15
+ spec.homepage = 'http://github.com/redbooth/departure'
16
+ spec.license = 'MIT'
17
+
18
+ spec.post_install_message = <<-MESSAGE
19
+ ! The Percona_migrator gem has been deprecated and has been replaced by Departure.
20
+ ! See: https://rubygems.org/gems/departure
21
+ ! And: https://github.com/redbooth/departure
22
+ MESSAGE
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_runtime_dependency 'rails', '~>3.2.22'
28
+ spec.add_runtime_dependency 'mysql2', '~>0.3.20'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
33
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
34
+ spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
35
+ end