migration-lock-timeout 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a619d10f5989579b9e6b7b9fecbbabe1da870e2
4
+ data.tar.gz: 2a8684a0d10cb2f62bdf61e267b01ac47e235e23
5
+ SHA512:
6
+ metadata.gz: 5ecc4823ab9b5a7c8e252c632225c2d009eb7fe3a560526ad3ac9407525c6943cb207b6cba02c269ffa4c8dfdea7ba983e97757620fe7a72192dc9d6d7906327
7
+ data.tar.gz: af060b85d9066224932b22b5f05412bb26680222ffe80f523af9a17e01fa337eca69aeeb6670dd5d7a09ccf0536b5779a185488b44884171114d0ffc50d5bd1b
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
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 opensource@procore.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
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in migration-lock-timeout.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Procore Technologies, Inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Migration Lock Timeout
2
+
3
+ [![CircleCI](https://circleci.com/gh/procore/migration-lock-timeout/tree/master.svg?style=svg&circle-token=db5501175f384dfa477f8bfa2bdc628efe781e98)](https://circleci.com/gh/procore/migration-lock-timeout/tree/master)
4
+
5
+ Migration Lock Timeout is a Ruby gem that adds a lock timeout to all Active
6
+ Record migrations in your Ruby on Rails project. A lock timeout sets a timeout
7
+ on how long PostgreSQL will wait to acquire a lock on tables being altered
8
+ before failing and rolling back. This prevents migrations from creating
9
+ additional lock contention that can take down your site when it's under heavy
10
+ load. Migration Lock Timeout currently only supports [PostgreSQL](https://www.postgresql.org/)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'migration-lock-timeout'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Configure the default lock timeout in a Rails initializer
23
+
24
+ ```ruby
25
+ #config/initializers/migration_lock_timeout.rb
26
+
27
+ MigrationLockTimeout.configure |config|
28
+ config.default_lock_timeout = 5 #timeout in seconds
29
+ end
30
+ ```
31
+
32
+ And that's all! Now every migration will execute
33
+ ```psql
34
+ SET LOCAL lock_timeout = '5s';
35
+ ```
36
+ inside the migration transaction before your migration code runs. No lock
37
+ timeout will be used for the `down` migration.
38
+
39
+ ## Disabling
40
+
41
+ You can disable the lock timeout by using:
42
+ ```ruby
43
+ class AddFoo < ActiveRecord::Migration
44
+
45
+ disable_lock_timeout!
46
+
47
+ def change
48
+ create_table :foo do |t|
49
+ t.timestamps
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ ## Custom lock timeout
56
+
57
+ You can change the duration of the lock timeout by using:
58
+ ```ruby
59
+ class AddBar < ActiveRecord::Migration
60
+
61
+ set_lock_timeout 10
62
+
63
+ def change
64
+ create_table :bar do |t|
65
+ t.timestamps
66
+ end
67
+ end
68
+ end
69
+ ```
70
+ Additionally, if you have not set a default lock timeout, you can use this to
71
+ set a timeout for a particular migration.
72
+
73
+ ## disable_ddl_transaction!
74
+
75
+ If you use `disable_ddl_transaction!`, no lock timeout will occur
76
+ ```ruby
77
+ class AddMonkey < ActiveRecord::Migration
78
+
79
+ disable_ddl_transaction!
80
+
81
+ def change
82
+ create_table :monkey do |t|
83
+ t.timestamps
84
+ end
85
+ end
86
+ end
87
+ ```
88
+
89
+ ## Running the specs
90
+
91
+ To run the specs you must have [PostgreSQL](https://www.postgresql.org/)
92
+ installed. Create a database called `migration_lock_timeout_test` and set the
93
+ environment variables `POSTGRES_DB_USERNAME` and `POSTGRES_DB_PASSWORD` then run
94
+ `rspec`
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/procore/migration-lock-timeout. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
104
+
105
+ ## About Procore
106
+
107
+ <img
108
+ src="https://www.procore.com/images/procore_logo.png"
109
+ alt="Procore Logo"
110
+ width="250px"
111
+ />
112
+
113
+ Migration Lock Timeout is maintained by Procore Technologies.
114
+
115
+ Procore - building the software that builds the world.
116
+
117
+ Learn more about the #1 most widely used construction management software at [procore.com](https://www.procore.com/)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "migration_lock_timeout"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,8 @@
1
+ machine:
2
+ environment:
3
+ POSTGRES_DB_DATABASE: circle_test
4
+ POSTGRES_DB_USERNAME: ubuntu
5
+ POSTGRES_DB_PASSWORD: ''
6
+ database:
7
+ override:
8
+ - echo 'using circle_test'
@@ -0,0 +1,9 @@
1
+ require 'active_record'
2
+
3
+ module MigrationLockTimeout
4
+ end
5
+
6
+ Dir[File.join(File.dirname(__FILE__), 'migration_lock_timeout', '*.rb')].each {|file| require file }
7
+
8
+ ::ActiveRecord::Migration.prepend(MigrationLockTimeout::LockManager)
9
+ ::ActiveRecord::Migration.extend(MigrationLockTimeout::MigrationExtensions)
@@ -0,0 +1,18 @@
1
+ module MigrationLockTimeout
2
+ mattr_accessor :config
3
+
4
+ def self.configure
5
+ @@config = Configurator.new
6
+ yield @@config
7
+ end
8
+
9
+ class Configurator
10
+ attr_accessor :default_timeout
11
+
12
+ def initialize
13
+ @default_timeout = nil
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,14 @@
1
+ module MigrationLockTimeout
2
+ module LockManager
3
+
4
+ def migrate(direction)
5
+ timeout_disabled = self.class.disable_lock_timeout
6
+ time = self.class.lock_timeout_override ||
7
+ MigrationLockTimeout.try(:config).try(:default_timeout)
8
+ if !timeout_disabled && direction == :up && time && !disable_ddl_transaction
9
+ execute "SET LOCAL lock_timeout = '#{time}s'"
10
+ end
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module MigrationLockTimeout
2
+ module MigrationExtensions
3
+ attr_accessor :disable_lock_timeout
4
+ attr_accessor :lock_timeout_override
5
+
6
+ def disable_lock_timeout!
7
+ self.disable_lock_timeout = true
8
+ end
9
+
10
+ def set_lock_timeout(seconds)
11
+ self.lock_timeout_override = seconds
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module MigrationLockTimeout
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'migration_lock_timeout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "migration-lock-timeout"
8
+ spec.version = MigrationLockTimeout::VERSION
9
+ spec.authors = ["Brad Urani"]
10
+ spec.email = ["bradurani@gmail.com", "opensource@procore.com"]
11
+
12
+ spec.summary = "Ruby gem that adds a lock timeout to Active Record migrations"
13
+ spec.description = "Ruby gem that automatically adds a lock timeout to all Active Record migrations"
14
+ spec.homepage = "http://github.com/procore/migration-lock-timeout"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 11.2.2"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pg"
34
+ spec.add_development_dependency "database_cleaner"
35
+ spec.add_development_dependency "pry"
36
+
37
+ spec.add_runtime_dependency "activerecord", "~>4.2"
38
+ end
data/spec_helper.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'database_cleaner'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ ActiveRecord::Base.establish_connection(
6
+ adapter: "postgresql",
7
+ database: ENV["POSTGRES_DB_DATABASE"] || "migration_lock_timeout_test",
8
+ username: ENV['POSTGRES_DB_USERNAME'],
9
+ password: ENV['POSTGRES_DB_PASSWORD'],
10
+ host: 'localhost'
11
+ )
12
+ DatabaseCleaner.strategy = :transaction
13
+ DatabaseCleaner.clean_with(:truncation)
14
+ end
15
+
16
+ config.around(:each) do |example|
17
+ DatabaseCleaner.cleaning do
18
+ example.run
19
+ end
20
+ end
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migration-lock-timeout
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brad Urani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 11.2.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 11.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.2'
111
+ description: Ruby gem that automatically adds a lock timeout to all Active Record
112
+ migrations
113
+ email:
114
+ - bradurani@gmail.com
115
+ - opensource@procore.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - circle.yml
131
+ - lib/migration-lock-timeout.rb
132
+ - lib/migration_lock_timeout/config.rb
133
+ - lib/migration_lock_timeout/lock_manager.rb
134
+ - lib/migration_lock_timeout/migration_extensions.rb
135
+ - lib/migration_lock_timeout/version.rb
136
+ - migration-lock-timeout.gemspec
137
+ - spec_helper.rb
138
+ homepage: http://github.com/procore/migration-lock-timeout
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ allowed_push_host: https://rubygems.org
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.6.6
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Ruby gem that adds a lock timeout to Active Record migrations
163
+ test_files: []