reversibility_checker 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d36081ec7bc7c4abb8a6ea04a967fa1e6dadf9a00f65f36b9d88edb41bb38cf
4
- data.tar.gz: 3afc569c9ef0064593a0acd3183a5e087be5d59f3cb298df8a1c64416c93d6f3
3
+ metadata.gz: c8716ded2cae0032c7edbbed7c8984b81d713d87fc6db20e65e78b127b96d492
4
+ data.tar.gz: ed5c4a55d4d0a22e56455b5ef97f1081f4825f84de998ddcc8a61f307d82bbb5
5
5
  SHA512:
6
- metadata.gz: 8113b44ad3f4f22265781c3f3e97c89100858bdd66d3868a27f2338157a34426cb7288fa1801f584c71f846cf4c12895c9762e89e304f1c0095b7b0d68cfdea6
7
- data.tar.gz: 2a1c04ada6b3349d18f55cc3a1849bfbeb1d1dac9a6a0431115fbcc0fb45bb9988ebd821d3170ae975a63711800c33c491a9a10aeb0c32cdaca94f9b9f7af30e
6
+ metadata.gz: 864547946fd5688164ba9f629d85518b8a48f93d9b3a56e5c711e58ec763306ca255fee03ec86ea65323e6c29845bfca70552de1ab71354be7516d6d50eb7e78
7
+ data.tar.gz: fa59da40b51345a7a53342e3a55e1fb1c0138ec71fe3e9a5f3fa8b316183a32d33870ad9cd5cb8d9af303bf4fbbab21751b948b4320b025024cee196e0f92142
data/README.md CHANGED
@@ -14,4 +14,49 @@ end
14
14
  $ rails db:migrate:check_reversibility
15
15
  ```
16
16
 
17
- This task check diffs between a current schema and a schema which migrated and rollbacked. If there are diffs, it will print the diffs and exit with exit status `1`.
17
+ This task checks diffs between a current schema and a schema which migrated and rollbacked. If there are diffs, it will print the diffs and exit with exit status `1`.
18
+
19
+ ## Example
20
+
21
+ if you create a following migration file,
22
+
23
+ ```rb
24
+ class ChangeEmailLimitAtUsers < ActiveRecord::Migration[5.2]
25
+ def up
26
+ change_column :users, :email, :string, limit: 50
27
+ end
28
+
29
+ def down
30
+ change_column :users, :email, :string
31
+ end
32
+ end
33
+ ```
34
+
35
+ when you run `db:migrate:check_reversibility` task, this task will run `db:migrate` and `db:rollback` and print diffs between a current schema and a rollbacked schema.
36
+
37
+ ```bash
38
+ $ rails db:migrate:check_reversibility
39
+ # This file is auto-generated from the current state of the database. Instead
40
+ # of editing this file, please use the migrations feature of Active Record to
41
+ # incrementally modify your database, and then regenerate this schema definition.
42
+ #
43
+ # Note that this schema.rb definition is the authoritative source for your
44
+ # database schema. If you need to create the application database on another
45
+ # system, you should be using db:schema:load, not running all the migrations
46
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
47
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
48
+ #
49
+ # It's strongly recommended that you check this file into your version control system.
50
+
51
+ ActiveRecord::Schema.define(version: 2018_10_17_064352) do
52
+
53
+ create_table "users", force: :cascade do |t|
54
+ t.string "name"
55
+ - t.string "email"
56
+ + t.string "email", limit: 50
57
+ t.datetime "created_at", null: false
58
+ t.datetime "updated_at", null: false
59
+ end
60
+
61
+ end
62
+ ```
@@ -1,6 +1,5 @@
1
1
  require "active_record"
2
2
  require "diffy"
3
- require "stringio"
4
3
 
5
4
  namespace :db do
6
5
  namespace :migrate do
@@ -28,19 +27,17 @@ namespace :db do
28
27
  ActiveRecord::Base.connection.migration_context.up(current_version)
29
28
 
30
29
  # Take a snapshot of the temporary schema
31
- current_buffer = StringIO.new
32
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, current_buffer)
30
+ current_schema = ReversibilityChecker.dump(config)
33
31
 
34
32
  # Migrate a temporary schema upto latest and rollback to current version
35
33
  ActiveRecord::Base.connection.migration_context.up
36
34
  ActiveRecord::Base.connection.migration_context.down(current_version)
37
35
 
38
36
  # Take a snapshot again
39
- rollbacked_buffer = StringIO.new
40
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, rollbacked_buffer)
37
+ rollbacked_schema = ReversibilityChecker.dump(config)
41
38
 
42
39
  # Compare two snapshots
43
- diff = Diffy::Diff.new(current_buffer.string, rollbacked_buffer.string)
40
+ diff = Diffy::Diff.new(current_schema, rollbacked_schema)
44
41
 
45
42
  if diff.count > 0
46
43
  Object::STDOUT.puts diff.to_s(:color)
@@ -1,3 +1,3 @@
1
1
  module ReversibilityChecker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,2 +1,20 @@
1
1
  require "reversibility_checker/railtie"
2
2
  require "reversibility_checker/version"
3
+
4
+ require "active_record"
5
+ require "stringio"
6
+
7
+ module ReversibilityChecker
8
+ def self.dump(config)
9
+ case ActiveRecord::Base.schema_format
10
+ when :ruby
11
+ buffer = StringIO.new
12
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, buffer)
13
+ buffer.string
14
+ when :sql
15
+ file = Tempfile.new
16
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, file.path)
17
+ file.read
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reversibility_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Kaneko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2018-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails