git-driver-merge-structure-sql 1.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7e61232c5b081e9fbaecaf0863159d88e404492a43ed1893306e946a6e5a8ddf
4
+ data.tar.gz: a7ef1741fa075f99ca06946e915a63dc8c1817570ebce7d2cda51e234dd3a55a
5
+ SHA512:
6
+ metadata.gz: 9ab42fcc95eb6509ddc249bca5367f87d8694b257785047d5a20e99bf411c466fa697465711ef9e18ac04da14f0eae4e7c8a2c8c36774897438cde59f2a33320
7
+ data.tar.gz: 2f0060eedf7c56845daa706e1733acc97e3ba71637cbceb2fc0b8349bc85228a0ea49131341eaa3b760dc421bc7591125472de5f7710924f363c8efe3ebbb471
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ Gemfile.lock
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Change Log
2
+
3
+ ## 1.0.0 (2018-11-29)
4
+
5
+ - Initial release
6
+
7
+ ## 1.1.0 (2018-11-30)
8
+
9
+ - Add support for the latest MySQL dump format
10
+ - Mention support for the SQLite3 dump format
11
+
12
+ ## 1.1.1 (2021-04-28)
13
+
14
+ - Fix installation when the attribute file does not exist yet
15
+
16
+ ## 1.1.2 (2021-04-30)
17
+
18
+ - Implemnt local installation with --install=local
19
+
20
+ ## 1.2.0 (2024-12-16)
21
+
22
+ - Implement reverse ordering
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in git-merge-structure-sql.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2018-2021 Akinori MUSHA
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # git-merge-structure-sql
2
+
3
+ This is a merge driver for Git that resolves typical merge conflicts
4
+ in a `db/structure.sql` file of Rails.
5
+
6
+ When your project is configured with
7
+ `config.active_record.schema_format = :sql`, the database schema is
8
+ kept in `db/structure.sql` instead of `db/schema.rb` in the native
9
+ dump format of the underlying database engine, which is not suitable
10
+ for the default merge driver of Git to deal with. As a result, when
11
+ you try to merge two branches you always have to resolve trivial
12
+ conflicts manually if new schema migrations take place in both
13
+ branches. This custom driver takes away such a pain.
14
+
15
+ Currently only PostgreSQL, MySQL and SQLite3 dump formats are
16
+ supported.
17
+
18
+ ## Installation
19
+
20
+ Run this:
21
+
22
+ $ gem install git-merge-structure-sql
23
+
24
+ And enable it yourself in your Git configuration, or let it do that
25
+ for you by this command:
26
+
27
+ $ git-merge-structure-sql --install
28
+
29
+ This adds necessary settings to your `~/.gitconfig` or
30
+ `$XDG_CONFIG_HOME/git/config` and the default gitattributes(5) file to
31
+ enable the merge driver for structure.sql files.
32
+
33
+ If you want to enable this driver only in the current git directory,
34
+ run this:
35
+
36
+ $ git-merge-structure-sql --install=local
37
+
38
+ ## Usage
39
+
40
+ Once enabled, Git should call this driver as necessary when it needs
41
+ to merge changes made in structure.sql.
42
+
43
+ ## History
44
+
45
+ See `CHANGELOG.md` for the version history.
46
+
47
+ ## Author
48
+
49
+ Copyright (c) 2018-2021 Akinori MUSHA.
50
+
51
+ Licensed under the 2-clause BSD license. See `LICENSE.txt` for
52
+ details.
53
+
54
+ Visit the [GitHub Repository](https://github.com/knu/sidetiq-timezone)
55
+ for the latest information.
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 "git-driver-merge-structure-sql"
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(__FILE__)
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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "git-driver-merge-structure-sql"
4
+
5
+ StructureSqlMergeDriver.new.main(*ARGV)
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "git-driver-merge-structure-sql"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git-driver-merge-structure-sql"
8
+ spec.version = StructureSqlMergeDriver::VERSION
9
+ spec.authors = ["Akinori MUSHA", "Joe Degler"]
10
+ spec.email = ["knu@idaemons.org", "joe@degler.dev"]
11
+ spec.license = "BSD-2-Clause"
12
+
13
+ spec.summary = %q{git merge driver for db/structure.sql in a Rails project. Originally forked from git-merge-structure-sql}
14
+ spec.homepage = "https://github.com/Joe-Degler/git-driver-merge-structure-sql"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/Joe-Degler/git-driver-merge-structure-sql/blob/master/CHANGELOG.md"
20
+ end
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.2"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,258 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # git-driver-merge-structure-sql - git merge driver for db/structure.sql in a Rails project
5
+ #
6
+ # How to use:
7
+ # $ git-driver-merge-structure-sql --install
8
+ #
9
+ # Copyright (c) 2018-2021 Akinori MUSHA
10
+ #
11
+ # All rights reserved.
12
+ #
13
+ # Redistribution and use in source and binary forms, with or without
14
+ # modification, are permitted provided that the following conditions
15
+ # are met:
16
+ # 1. Redistributions of source code must retain the above copyright
17
+ # notice, this list of conditions and the following disclaimer.
18
+ # 2. Redistributions in binary form must reproduce the above copyright
19
+ # notice, this list of conditions and the following disclaimer in the
20
+ # documentation and/or other materials provided with the distribution.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32
+ # SUCH DAMAGE.
33
+ #
34
+
35
+ class StructureSqlMergeDriver
36
+ VERSION = '1.2.0'
37
+ VARIANTS = []
38
+
39
+ module Default # This covers PostgreSQL, SQLite and newer MySQL formats.
40
+ RE_VERSION = /^\('(\d+)'\)[,;]\n/
41
+ RE_VERSIONS = /^INSERT INTO (?<q>["`])schema_migrations\k<q> \(version\) VALUES\n\K#{RE_VERSION}+/
42
+
43
+ class << self
44
+ def match?(content)
45
+ RE_VERSIONS === content
46
+ end
47
+
48
+ def merge!(*contents)
49
+ merge_versions!(*contents)
50
+ end
51
+
52
+ private
53
+
54
+ def merge_versions!(*contents)
55
+ replacement = format_versions(
56
+ contents.inject([]) { |versions, content|
57
+ versions | content[RE_VERSIONS].scan(RE_VERSION).flatten
58
+ }.sort.reverse
59
+ )
60
+
61
+ contents.each { |content|
62
+ content.sub!(RE_VERSIONS, replacement)
63
+ }
64
+ end
65
+
66
+ def format_versions(versions)
67
+ versions.map { |version| "('%s')" % version }.join(",\n") << ";\n"
68
+ end
69
+ end
70
+
71
+ VARIANTS.unshift self
72
+ end
73
+
74
+ module MySQL
75
+ class << self
76
+ RE_DUMP_TIMESTAMP = /^-- Dump completed on \K.+$/
77
+ RE_AUTO_INCREMENT_VALUE = /^\)(?= ).*\K AUTO_INCREMENT=\d+(?=.*;$)/
78
+ RE_VERSION = /^INSERT INTO schema_migrations \(version\) VALUES \('(\d+)'\);\s+/
79
+ RE_VERSIONS = /#{RE_VERSION}+/
80
+
81
+ def match?(content)
82
+ /^-- MySQL dump / === content
83
+ end
84
+
85
+ def merge!(*contents)
86
+ merge_dump_timestamps!(*contents)
87
+ scrub_auto_increment_values!(*contents)
88
+ merge_versions!(*contents)
89
+ end
90
+
91
+ private
92
+
93
+ def merge_dump_timestamps!(*contents)
94
+ replacement = contents.inject('') { |timestamp, content|
95
+ [timestamp, *content.scan(RE_DUMP_TIMESTAMP)].max rescue ''
96
+ }
97
+
98
+ unless replacement.empty?
99
+ contents.each { |content|
100
+ content.gsub!(RE_DUMP_TIMESTAMP, replacement)
101
+ }
102
+ end
103
+ end
104
+
105
+ def scrub_auto_increment_values!(*contents)
106
+ contents.each { |content|
107
+ content.gsub!(RE_AUTO_INCREMENT_VALUE, '')
108
+ }
109
+ end
110
+
111
+ def merge_versions!(*contents)
112
+ replacement = format_versions(
113
+ contents.inject([]) { |versions, content|
114
+ versions | content.scan(RE_VERSION).flatten
115
+ }.sort.reverse
116
+ )
117
+
118
+ contents.each { |content|
119
+ content.sub!(RE_VERSIONS, replacement)
120
+ }
121
+ end
122
+
123
+ def format_versions(versions)
124
+ versions.map { |version| "INSERT INTO schema_migrations (version) VALUES ('%s');\n\n" % version }.join
125
+ end
126
+ end
127
+
128
+ VARIANTS.unshift self
129
+ end
130
+
131
+ def system!(*args)
132
+ system(*args) or exit $?.exitstatus
133
+ end
134
+
135
+ def main(*argv)
136
+ require 'optparse'
137
+ require 'shellwords'
138
+
139
+ myname = File.basename($0)
140
+ driver_name = 'merge-structure-sql'
141
+
142
+ banner = <<~EOF
143
+ #{myname} - git merge driver for db/structure.sql in a Rails project #{VERSION}
144
+
145
+ usage: #{myname} <current-file> <base-file> <other-file>
146
+ #{myname} --install
147
+
148
+ EOF
149
+
150
+ install = false
151
+
152
+ opts = OptionParser.new(banner) { |opts|
153
+ opts.version = VERSION
154
+ opts.summary_indent = ''
155
+ opts.summary_width = 24
156
+
157
+ opts.on('--install[={global|local}]',
158
+ "Enable this merge driver in Git (default: global)") { |val|
159
+ case install = val&.to_sym || :global
160
+ when :global, :local
161
+ # ok
162
+ else
163
+ raise OptionParser::InvalidArgument, "--install=#{val}: unknown argument"
164
+ end
165
+ }
166
+ }
167
+
168
+ files = opts.order(argv)
169
+
170
+ if install
171
+ global = install == :global
172
+
173
+ git_config = ["git", "config", *("--global" if global)]
174
+
175
+ config_file = `GIT_EDITOR=echo #{git_config.shelljoin} -e 2>/dev/null`.chomp
176
+
177
+ puts "#{config_file}: Adding the \"#{driver_name}\" driver definition"
178
+
179
+ system!(
180
+ *git_config,
181
+ "merge.#{driver_name}.name",
182
+ "Rails structure.sql merge driver"
183
+ )
184
+ system!(
185
+ *git_config,
186
+ "merge.#{driver_name}.driver",
187
+ "#{myname.shellescape} %A %O %B"
188
+ )
189
+
190
+ attributes_file =
191
+ if global
192
+ filename = `git config --global core.attributesfile`.chomp
193
+
194
+ if $?.success?
195
+ File.expand_path(filename)
196
+ else
197
+ [
198
+ [File.join(ENV['XDG_CONFIG_HOME'] || '~/.config', 'git'), 'attributes'],
199
+ ['~', '.gitattributes']
200
+ ].find { |dir, file|
201
+ if File.directory?(File.expand_path(dir))
202
+ system!(*%W[
203
+ git config --global core.attributesfile #{File.join(dir, file)}
204
+ ])
205
+ break File.expand_path(file, dir)
206
+ end
207
+ } or raise "don't you have home?"
208
+ end
209
+ else
210
+ git_dir = `git rev-parse --git-dir`.chomp
211
+
212
+ if $?.success?
213
+ File.expand_path(File.join('info', 'attributes'), git_dir)
214
+ else
215
+ raise "not in a git directory"
216
+ end
217
+ end
218
+
219
+ File.open(attributes_file, 'a+') { |f|
220
+ pattern = /^\s*structure.sql\s+(?:\S+\s+)*merge=#{Regexp.quote(driver_name)}(?:\s|$)/
221
+ break if f.any? { |line| pattern === line }
222
+
223
+ puts "#{attributes_file}: Registering the \"#{driver_name}\" driver for structure.sql"
224
+ f.puts if f.pos > 0
225
+ f.puts "structure.sql merge=#{driver_name}"
226
+ }
227
+
228
+ exit
229
+ end
230
+
231
+ unless files.size == 3
232
+ STDERR.print opts.help
233
+ exit 64
234
+ end
235
+
236
+ contents = files.map { |file| File.read(file) }
237
+
238
+ sample = contents[0]
239
+ if variant = VARIANTS.find { |v| v.match?(sample) }
240
+ variant.merge!(*contents)
241
+
242
+ files.zip(contents) do |file, content|
243
+ File.write(file, content)
244
+ end
245
+ else
246
+ STDERR.puts "#{myname}: Unsupported format; falling back to git-merge-file(1)"
247
+ end
248
+
249
+ exec(*%W[git merge-file -q], *files)
250
+ rescue => e
251
+ STDERR.puts "#{myname}: #{e.message}"
252
+ exit 1
253
+ end
254
+ end
255
+
256
+ if $0 == __FILE__
257
+ StructureSqlMergeDriver.new.main(*ARGV)
258
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-driver-merge-structure-sql
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Akinori MUSHA
8
+ - Joe Degler
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2024-12-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.2'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '13.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '13.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ description:
57
+ email:
58
+ - knu@idaemons.org
59
+ - joe@degler.dev
60
+ executables:
61
+ - git-driver-merge-structure-sql
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - CHANGELOG.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - exe/git-driver-merge-structure-sql
76
+ - git-driver-merge-structure-sql.gemspec
77
+ - lib/git-driver-merge-structure-sql.rb
78
+ homepage: https://github.com/Joe-Degler/git-driver-merge-structure-sql
79
+ licenses:
80
+ - BSD-2-Clause
81
+ metadata:
82
+ homepage_uri: https://github.com/Joe-Degler/git-driver-merge-structure-sql
83
+ source_code_uri: https://github.com/Joe-Degler/git-driver-merge-structure-sql
84
+ changelog_uri: https://github.com/Joe-Degler/git-driver-merge-structure-sql/blob/master/CHANGELOG.md
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.5.16
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: git merge driver for db/structure.sql in a Rails project. Originally forked
104
+ from git-merge-structure-sql
105
+ test_files: []