ar-sequence 0.1.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
+ SHA256:
3
+ metadata.gz: 8e2607e8d6463d0bb957a18045b725e95efbea7fc58ca7b7f07eb729aa397690
4
+ data.tar.gz: 04462fb01f394a0429d0139f964e7e71c9f99b97b82022a415c02d4b3e5653fd
5
+ SHA512:
6
+ metadata.gz: 484ae05bdbb6518bac4f228e6b2b70bb1874cdcf36ed85572ca5866d5c2f3f410a42a173f2d6d32ccb58ab79908e094873e78868f778c252dad676a58ecaa144
7
+ data.tar.gz: 5ae496444d6f50b5c05ad4273ba236f8508dc1cd6b3c57847d9b92d5b34252c302e8c2393e6b461726c1245ca0ff7ebaabd522c01d97951e39f4430eac58f922
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,31 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ before_install:
5
+ - gem install bundler
6
+ before_script:
7
+ - createdb test
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ after_script:
12
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
13
+ gemfile:
14
+ - Gemfile
15
+ - gemfiles/activerecord_5_2.gemfile
16
+ - gemfiles/activerecord_5_1.gemfile
17
+ - gemfiles/activerecord_5_0.gemfile
18
+ addons:
19
+ postgresql: '10'
20
+ apt:
21
+ packages:
22
+ - postgresql-10
23
+ - postgresql-client-10
24
+ rvm:
25
+ - 2.5.1
26
+ notifications:
27
+ email: false
28
+ env:
29
+ global:
30
+ - PGPORT=5433
31
+ - secure: tJIhjywY5r1oi4ShGqAoy+Jg17u+K9KfZtvC2lGmlhd9v5sU+MmuFZqoJAM1sGSY6UTsMfKs6vifyEGnVtawv1VK1RnNzQNWCUrm/hqdNDvayIh4m4oDt27EWj6cgh5roc6Y8knmkup+rXGQiVUmUgMjjF0NhLYZPgp6UPC5NhozEE8Y31Cv0M2UUnz460XyBQAvCPq7z7/rrTVJN84ioV755U/UiingIn16RG5A13TN3xTJbIhmxFcJpn8edX7H3DUSsDafKn4e+tiTXg0WnOFTTR9P1D3kah86AT7kvf4s/6ETRnZm+Rnv30ZNIQaTFlJv6zHTCzmLsRJ4CTUFHgjIrsDbOFeZmpgxSJg5sYFPgNsNh+BovWZuWoKgSkZXh0NaFhiGhQivd4/HwX45W4BybS1/Bm79mG25k14xbQUlMXZA5gRFA3v+ih4lxDNp5YqXJJhrs4ApSOuUsPJrp/JCKZkTzKXvOgNm8EvZtZrnkEeSItbq8M20m2N38bCq/uNU+h0gCknLsoheRGB/JvOI+uBehwWAITwcaUlZPHu4/n+ASKufaqeWfZRnSEA04fIkpT4H03O8zWZwvJ+gnuEbh0t/eLOTLOJOINuT9qwgduobWyBqQC+RkkHBFEV6fFH2yld8RwCXZNu3g1q40OBN4dvvMp/8VZEVxSB0I74=
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # ar-sequence
2
+
3
+ #### v0.1.0
4
+
5
+ - Initial release
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ar-sequence.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nando Vieira
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.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # AR::Sequence
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/ar-sequence.png)](https://travis-ci.org/fnando/ar-sequence)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/ar-sequence/badges/gpa.svg)](https://codeclimate.com/github/fnando/ar-sequence)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/ar-sequence/badges/coverage.svg)](https://codeclimate.com/github/fnando/ar-sequence/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/ar-sequence.svg)](https://rubygems.org/gems/ar-sequence)
7
+ [![Gem](https://img.shields.io/gem/dt/ar-sequence.svg)](https://rubygems.org/gems/ar-sequence)
8
+
9
+ Add support for PostgreSQL's SEQUENCE on ActiveRecord migrations.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem "ar-sequence"
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install ar-sequence
26
+
27
+ ## Usage
28
+
29
+ To create a `SEQUENCE`, just use the method `create_sequence`.
30
+
31
+ ```ruby
32
+ class CreateUsers < ActiveRecord::Migration[5.2]
33
+ def up
34
+ create_sequence :position
35
+ end
36
+
37
+ def down
38
+ drop_sequence :position
39
+ end
40
+ end
41
+ ```
42
+
43
+ You can also specify the initial value and increment:
44
+
45
+ ```ruby
46
+ create_sequence :position, increment: 2
47
+ create_sequence :position, start: 100
48
+ ```
49
+
50
+ To define a column that has a sequence as its default value, use something like the following:
51
+
52
+ ```ruby
53
+ class CreateThings < ActiveRecord::Migration[5.2]
54
+ def change
55
+ create_sequence :position
56
+
57
+ create_table :things do |t|
58
+ t.text :name
59
+
60
+ # PostgreSQL uses bigint as the sequence's default type.
61
+ # Use a block to specify the default value on migrations.
62
+ t.bigint :position,
63
+ null: false,
64
+ default: -> { "nextval('position')" }
65
+
66
+ t.timestamps
67
+ end
68
+ end
69
+ end
70
+ ```
71
+
72
+ This gem also adds a few helpers to interact with `SEQUENCE`s.
73
+
74
+ ```ruby
75
+ ActiveRecord::Base.nextval("position") # Advance sequence and return new value
76
+ ActiveRecord::Base.currval("position") # Return value most recently obtained with nextval for specified sequence.
77
+ ActiveRecord::Base.setval("position", 1234) # Set sequence's current value
78
+ ```
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/ar-sequence. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
89
+
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
94
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ t.verbose = false
9
+ t.warning = false
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,30 @@
1
+ require "./lib/ar/sequence/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ar-sequence"
5
+ spec.version = AR::Sequence::VERSION
6
+ spec.authors = ["Nando Vieira"]
7
+ spec.email = ["fnando.vieira@gmail.com"]
8
+
9
+ spec.summary = "Add support for PostgreSQL's SEQUENCE on ActiveRecord migrations"
10
+ spec.description = spec.summary
11
+ spec.homepage = "https://rubygems.org/gems/ar-sequence"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`
15
+ .split("\x0")
16
+ .reject {|f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest-utils"
26
+ spec.add_development_dependency "pg"
27
+ spec.add_development_dependency "pry-meta"
28
+ spec.add_development_dependency "codeclimate-test-reporter"
29
+ spec.add_development_dependency "simplecov"
30
+ end
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ ar-sequence (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.0.7)
11
+ activesupport (= 5.0.7)
12
+ activerecord (5.0.7)
13
+ activemodel (= 5.0.7)
14
+ activesupport (= 5.0.7)
15
+ arel (~> 7.0)
16
+ activesupport (5.0.7)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ arel (7.1.4)
22
+ awesome_print (1.8.0)
23
+ byebug (10.0.2)
24
+ codeclimate-test-reporter (1.0.8)
25
+ simplecov (<= 0.13)
26
+ coderay (1.1.2)
27
+ concurrent-ruby (1.0.5)
28
+ docile (1.1.5)
29
+ i18n (1.1.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.1.0)
32
+ method_source (0.9.0)
33
+ minitest (5.11.3)
34
+ minitest-utils (0.4.1)
35
+ minitest
36
+ pg (1.1.3)
37
+ pry (0.11.3)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.6.0)
41
+ byebug (~> 10.0)
42
+ pry (~> 0.10)
43
+ pry-meta (0.0.10)
44
+ awesome_print
45
+ pry
46
+ pry-byebug
47
+ pry-remote
48
+ pry-remote (0.1.8)
49
+ pry (~> 0.9)
50
+ slop (~> 3.0)
51
+ rake (12.3.1)
52
+ simplecov (0.13.0)
53
+ docile (~> 1.1.0)
54
+ json (>= 1.8, < 3)
55
+ simplecov-html (~> 0.10.0)
56
+ simplecov-html (0.10.2)
57
+ slop (3.6.0)
58
+ thread_safe (0.3.6)
59
+ tzinfo (1.2.5)
60
+ thread_safe (~> 0.1)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ activerecord (~> 5.0.0)
67
+ ar-sequence!
68
+ bundler
69
+ codeclimate-test-reporter
70
+ minitest-utils
71
+ pg
72
+ pry-meta
73
+ rake
74
+ simplecov
75
+
76
+ BUNDLED WITH
77
+ 1.16.4
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "activerecord", "~> 5.0.0"
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ ar-sequence (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.1.6)
11
+ activesupport (= 5.1.6)
12
+ activerecord (5.1.6)
13
+ activemodel (= 5.1.6)
14
+ activesupport (= 5.1.6)
15
+ arel (~> 8.0)
16
+ activesupport (5.1.6)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ arel (8.0.0)
22
+ awesome_print (1.8.0)
23
+ byebug (10.0.2)
24
+ codeclimate-test-reporter (1.0.8)
25
+ simplecov (<= 0.13)
26
+ coderay (1.1.2)
27
+ concurrent-ruby (1.0.5)
28
+ docile (1.1.5)
29
+ i18n (1.1.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.1.0)
32
+ method_source (0.9.0)
33
+ minitest (5.11.3)
34
+ minitest-utils (0.4.1)
35
+ minitest
36
+ pg (1.1.3)
37
+ pry (0.11.3)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.6.0)
41
+ byebug (~> 10.0)
42
+ pry (~> 0.10)
43
+ pry-meta (0.0.10)
44
+ awesome_print
45
+ pry
46
+ pry-byebug
47
+ pry-remote
48
+ pry-remote (0.1.8)
49
+ pry (~> 0.9)
50
+ slop (~> 3.0)
51
+ rake (12.3.1)
52
+ simplecov (0.13.0)
53
+ docile (~> 1.1.0)
54
+ json (>= 1.8, < 3)
55
+ simplecov-html (~> 0.10.0)
56
+ simplecov-html (0.10.2)
57
+ slop (3.6.0)
58
+ thread_safe (0.3.6)
59
+ tzinfo (1.2.5)
60
+ thread_safe (~> 0.1)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ activerecord (~> 5.1.0)
67
+ ar-sequence!
68
+ bundler
69
+ codeclimate-test-reporter
70
+ minitest-utils
71
+ pg
72
+ pry-meta
73
+ rake
74
+ simplecov
75
+
76
+ BUNDLED WITH
77
+ 1.16.4
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "activerecord", "~> 5.1.0"
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "activerecord", "~> 5.2.0"
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ ar-sequence (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.1)
11
+ activesupport (= 5.2.1)
12
+ activerecord (5.2.1)
13
+ activemodel (= 5.2.1)
14
+ activesupport (= 5.2.1)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ arel (9.0.0)
22
+ awesome_print (1.8.0)
23
+ byebug (10.0.2)
24
+ codeclimate-test-reporter (1.0.8)
25
+ simplecov (<= 0.13)
26
+ coderay (1.1.2)
27
+ concurrent-ruby (1.0.5)
28
+ docile (1.1.5)
29
+ i18n (1.1.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.1.0)
32
+ method_source (0.9.0)
33
+ minitest (5.11.3)
34
+ minitest-utils (0.4.1)
35
+ minitest
36
+ pg (1.1.3)
37
+ pry (0.11.3)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.6.0)
41
+ byebug (~> 10.0)
42
+ pry (~> 0.10)
43
+ pry-meta (0.0.10)
44
+ awesome_print
45
+ pry
46
+ pry-byebug
47
+ pry-remote
48
+ pry-remote (0.1.8)
49
+ pry (~> 0.9)
50
+ slop (~> 3.0)
51
+ rake (12.3.1)
52
+ simplecov (0.13.0)
53
+ docile (~> 1.1.0)
54
+ json (>= 1.8, < 3)
55
+ simplecov-html (~> 0.10.0)
56
+ simplecov-html (0.10.2)
57
+ slop (3.6.0)
58
+ thread_safe (0.3.6)
59
+ tzinfo (1.2.5)
60
+ thread_safe (~> 0.1)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ activerecord (~> 5.2.0)
67
+ ar-sequence!
68
+ bundler
69
+ codeclimate-test-reporter
70
+ minitest-utils
71
+ pg
72
+ pry-meta
73
+ rake
74
+ simplecov
75
+
76
+ BUNDLED WITH
77
+ 1.16.4
@@ -0,0 +1 @@
1
+ require "ar/sequence"
@@ -0,0 +1,21 @@
1
+ require "active_support/all"
2
+ require "active_record"
3
+ require "active_record/connection_adapters/postgresql_adapter"
4
+ require "active_record/connection_adapters/postgresql/schema_dumper"
5
+ require "active_record/migration/command_recorder"
6
+ require "active_record/schema_dumper"
7
+ require "ar/sequence/version"
8
+
9
+ module AR
10
+ module Sequence
11
+ require "ar/sequence/command_recorder"
12
+ require "ar/sequence/adapter"
13
+ require "ar/sequence/schema_dumper"
14
+ require "ar/sequence/model_methods"
15
+ end
16
+ end
17
+
18
+ ActiveRecord::Migration::CommandRecorder.include AR::Sequence::CommandRecorder
19
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include AR::Sequence::Adapter
20
+ ActiveRecord::SchemaDumper.prepend AR::Sequence::SchemaDumper
21
+ ActiveRecord::Base.extend AR::Sequence::ModelMethods
@@ -0,0 +1,30 @@
1
+ module AR
2
+ module Sequence
3
+ module Adapter
4
+ def check_sequences
5
+ select_all("SELECT * FROM information_schema.sequences").to_a
6
+ end
7
+
8
+ def create_sequence(name, options = {})
9
+ increment = options[:increment] || options[:step]
10
+ name = quote_column_name(name)
11
+
12
+ sql = ["CREATE SEQUENCE IF NOT EXISTS #{name}"]
13
+ sql << "INCREMENT BY #{increment}" if increment
14
+ sql << "START WITH #{options[:start]}" if options[:start]
15
+
16
+ execute(sql.join("\n"))
17
+ end
18
+
19
+ # Drop a sequence by its name.
20
+ #
21
+ # drop_sequence :user_position
22
+ #
23
+ def drop_sequence(name)
24
+ name = quote_column_name(name)
25
+ sql = "DROP SEQUENCE #{name}"
26
+ execute(sql)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ module AR
2
+ module Sequence
3
+ module CommandRecorder
4
+ # Usage:
5
+ #
6
+ # create_sequence :user_position
7
+ #
8
+ def create_sequence(name, options = {})
9
+ record(__method__, [name, options])
10
+ end
11
+
12
+ # Usage:
13
+ #
14
+ # drop_sequence :user_position
15
+ #
16
+ def drop_sequence(name)
17
+ record(__method__, [name])
18
+ end
19
+
20
+ def invert_create_sequence(args)
21
+ name, _ = args
22
+ [:drop_sequence, [name]]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module AR
2
+ module Sequence
3
+ module ModelMethods
4
+ def nextval(name)
5
+ name = connection.quote(name)
6
+ connection.execute("SELECT nextval(#{name})").first["nextval"]
7
+ end
8
+
9
+ def currval(name)
10
+ name = connection.quote(name)
11
+ connection.execute("SELECT currval(#{name})").first["currval"]
12
+ end
13
+
14
+ def setval(name, value)
15
+ name = connection.quote(name)
16
+ connection.execute("SELECT setval(#{name}, #{value})")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module AR
2
+ module Sequence
3
+ module SchemaDumper
4
+ def header(stream)
5
+ super
6
+ sequences(stream)
7
+ end
8
+
9
+ def sequences(stream)
10
+ sequences = @connection.check_sequences
11
+ return if sequences.empty?
12
+
13
+ sequences.each do |seq|
14
+ start_value = seq["start_value"]
15
+ increment = seq["increment"]
16
+
17
+ options = []
18
+ options << "start: #{start_value}" if start_value && Integer(start_value) != 1
19
+ options << "increment: #{increment}" if increment && Integer(increment) != 1
20
+
21
+ statement = ["create_sequence", seq["sequence_name"].inspect].join(" ")
22
+ statement << (options.any? ? ", " << options.join(", ") : "") if options.any?
23
+
24
+ stream.puts " #{statement}"
25
+ end
26
+
27
+ stream.puts
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module AR
2
+ module Sequence
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ar-sequence
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-utils
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: pg
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-meta
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: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Add support for PostgreSQL's SEQUENCE on ActiveRecord migrations
126
+ email:
127
+ - fnando.vieira@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CHANGELOG.md
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - ar-sequence.gemspec
141
+ - gemfiles/activerecord_5_0.Gemfile.lock
142
+ - gemfiles/activerecord_5_0.gemfile
143
+ - gemfiles/activerecord_5_1.Gemfile.lock
144
+ - gemfiles/activerecord_5_1.gemfile
145
+ - gemfiles/activerecord_5_2.gemfile
146
+ - gemfiles/activerecord_5_2.gemfile.lock
147
+ - lib/ar-sequence.rb
148
+ - lib/ar/sequence.rb
149
+ - lib/ar/sequence/adapter.rb
150
+ - lib/ar/sequence/command_recorder.rb
151
+ - lib/ar/sequence/model_methods.rb
152
+ - lib/ar/sequence/schema_dumper.rb
153
+ - lib/ar/sequence/version.rb
154
+ homepage: https://rubygems.org/gems/ar-sequence
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.7.6
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Add support for PostgreSQL's SEQUENCE on ActiveRecord migrations
178
+ test_files: []