systematize 0.0.1 โ†’ 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39619b8bfa011bf992c002bf266e3cc87e074d0c
4
- data.tar.gz: 5a1f88232472a5ec70e5d795448b59a93f5beb7d
3
+ metadata.gz: bd5c0b0659f114baf943c91a9a2bf4a38c255f1a
4
+ data.tar.gz: cea63ac2678319df2f8dcc85b0874892751bfc17
5
5
  SHA512:
6
- metadata.gz: 51c3ab97157d5853c4c1d55e9d92396212094d7669b115d30ba0ae1438cfbc3c1ad216af673711cba9745ac8c40bfc229039416b14dc42608d2ea7a4ad65dbf5
7
- data.tar.gz: 2ab08ea9995723e086409e78fe4741a0386b7a16cacb332e4f1b9c33bd0a409bf4180eb686e10460daddfdc8f42aef81d150ef65805e4360fdff3532d944c354
6
+ metadata.gz: 884b4ddf2e107c5b1391133fc26139687b9a23c48d5c305e91ef095ed4c30864053ae1c2587f725618fe2398e64ffec1e0fba71768155fd9d947db04882e3b3d
7
+ data.tar.gz: 976f29be93ac59ef3769342e37be708d6e9e781c518675d23d248810ad9616125dee1c5b57d252fc2014050fcb2da76685b4ce1816c8344b35c8c9209d3d3cf2
data/README.md CHANGED
@@ -1,64 +1,85 @@
1
1
  # systematize
2
2
 
3
- ![shuffler.gif](https://s15.postimg.org/jupy0v0or/shuffler.gif)
3
+ <p align="center">
4
+ <img src="https://s15.postimg.org/jupy0v0or/shuffler.gif" width="100%" />
5
+ </p>
4
6
 
5
- One of the most important things that a ruby application can have are the migrations, but they can be one of 2 kinds:
6
- - Structural migrations
7
- - Data migrations
8
-
9
- If you want to organize said migrations in their purpose you'll probably have a folder for the struture ones and another for the data ones. But with that separation comes a problem, when should you run one type and when to run the other?
10
- Probably the sanner way of doing it is we firstly run the structure migrations and after that we run the data migrations, but with this approach one problem will rise:
11
-
12
- What if I have a new field that is initially populated taking into account another field, and after that we can delete that other field?
13
- Imagine the following scenario:
14
- - You have a `Post` model that initially has a boolean field called `:deleted`.
15
- - After some time, and some deleted `Posts`, you need to know when that post has been deleted. So you create a `:deleted_at` field that will contain the time os the deletion.
16
- - You can now delete the old `:deleted` field because it turned obsolete, so you create the migration to do it.
17
-
18
- On this scenario we will have 2 structure migrations (create the `:deleted_at` field and removing the `:deleted` field) and a data migration (go through all the Posts and add the time to `:deleted_at` if they are `:deleted`). With previous migration approach, running all the migrations would fail because when the data migration run we would have the `:deleted` field because it was deleted by the structure migration.
7
+ ## Why does this even exist ?
19
8
 
20
- This is when `systematize` comes in for the rescue ๐Ÿš€
9
+ So you can seperate the data and structure migrations in different folders, because you know organization and stuff.
21
10
 
22
11
  ## Installation
23
12
 
24
- If your using a Gemfile, just add it to your project
25
- <pre><code>#Gemfile
13
+ If you're using a `Gemfile`, just add it to your project
14
+ ```gemfile
15
+ #Gemfile
26
16
  gem 'systematize'
27
- </code></pre>
17
+ ```
28
18
 
29
19
  Or just add it via `bundler`
30
- <pre><code>bundle install 'systematize'</code></pre>
20
+ ```gemfile
21
+ bundle install 'systematize'
22
+ ```
31
23
 
32
24
  ## Structure
33
25
  So as the structural migrations live in the `db/migrate` folder, the data migrations shall live in the `db/data` folder:
34
26
 
35
- <pre><code>- app
27
+ ```gemfile
28
+ - app
36
29
  |
37
30
  |-db
38
31
  |-data
39
32
  |-migrate
40
- </pre></code>
33
+ ```
41
34
 
42
35
  ## Usage
43
- After installing you'll se the following tasks pop-up:
36
+ After installing you'll see the following tasks pop-up:
44
37
 
45
- <pre><code>$> bundle exec rake -T
38
+ ```bash
39
+ $> bundle exec rake -T
46
40
  rake systematize:migrate # Migrate the database
47
41
  rake systematize:rollback # Rollback the database (options: STEP=x, VERBOSE=false)
48
42
  rake systematize:rollback_all # Rollback all the database
49
- </pre></code>
43
+ ```
50
44
 
51
45
  Now if you need to migrate the database you just need to run:
52
- <pre><code>bundle exec rake systematize:migrate</pre></code>
46
+ ```bash
47
+ bundle exec rake systematize:migrate
48
+ ```
53
49
 
54
50
  Needing to rollback the previous migration? No problem.
55
- <pre><code>bundle exec rake systematize:rollback</pre></code>
51
+ ```bash
52
+ bundle exec rake systematize:rollback
53
+ ```
56
54
 
57
55
  Need to rollback 2/3/4 migrations? I got you.
58
- <pre><code>bundle exec rake systematize:rollback STEP=2 </pre></code>
56
+ ```bash
57
+ bundle exec rake systematize:rollback STEP=2
58
+ ```
59
+
60
+ Made a mess so big you need to start fresh? Do it. (the migrations need to be reversible ๐Ÿ˜…)
61
+ ```bash
62
+ bundle exec rake systematize:rollback_all
63
+ ```
59
64
 
60
- Made a mess so big you need to start fresh? Do it. (the migrations need to be reversible :smile:)
61
- <pre><code>bundle exec rake systematize:rollback_all </pre></code>
65
+ ## Why was this frankstein created ? ๐Ÿ‘น
66
+
67
+ One of the most important things that a ruby application can have are the migrations, but they can be one of 2 kinds:
68
+ - Structural migrations
69
+ - Data migrations
70
+
71
+ If you want to organize said migrations in their purpose you'll probably have a folder for the struture ones and another for the data ones. But with that separation comes a problem, when should you run one type and when to run the other?
72
+ Probably the sanner way of doing it is we firstly run the structure migrations and after that we run the data migrations, but with this approach one problem will rise:
73
+
74
+ What if I have a new field that is initially populated taking into account another field, and after that we can delete that other field?
75
+ Imagine the following scenario:
76
+ - You have a `Post` model that initially has a boolean field called `:deleted`.
77
+ - After some time, and some deleted `Posts`, you need to know when that post has been deleted. So you create a `:deleted_at` field that will contain the time of the deletion.
78
+ - You can now delete the old `:deleted` field because it turned obsolete, so you create the migration to do it.
79
+
80
+ On this scenario we will have 2 structure migrations (create the `:deleted_at` field and removing the `:deleted` field) and a data migration (go through all the Posts and add the time to `:deleted_at` if they are `:deleted`). With previous migration approach, running all the migrations would fail because when the data migration run we wouldn't have the `:deleted` field because it was deleted by the structure migration.
81
+
82
+ This is when `systematize` comes in for the rescue ๐Ÿš€
62
83
 
63
84
  ## Caveats
64
85
  - The migrations need to follow the Rails convention to them `YYYYMMDDHHMMSS_create_products.rb`
@@ -67,3 +88,14 @@ Made a mess so big you need to start fresh? Do it. (the migrations need to be re
67
88
  ## TODO
68
89
  - [ ] Customizable folder configuration
69
90
  - [ ] Customizable transaction type configuration
91
+
92
+ ## Contributing
93
+ I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
94
+ 1. If its a feature, bugfix, or anything please only change code to what you specify.
95
+ 2. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
96
+ 3. Pull requests _must_ be made against `develop` branch. Any other branch (unless specified by the maintainers) will get rejected.
97
+ 4. Check for existing [issues](https://github.com/brazunisdelamancha/milagre/issues) first, before filing an issue.
98
+ 5. Have fun!
99
+
100
+ ### Created & Maintained By
101
+ [Ricardo Brazรฃo](https://github.com/RicardoBrazao) ([@RicBrazao](https://www.twitter.com/RicBrazao))
@@ -1,3 +1,3 @@
1
1
  module Systematize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,4 +24,14 @@ namespace :systematize do
24
24
  ActiveRecord::Migrator.migrate(temp_folder, 0)
25
25
  end
26
26
  end
27
+
28
+ desc "Create the database"
29
+ task :create => :environment do
30
+ Rake::Task["db:create"].invoke
31
+ end
32
+
33
+ desc "Drop the database"
34
+ task :drop => :environment do
35
+ Rake::Task["db:drop"].invoke
36
+ end
27
37
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,24 @@
1
1
  require 'rspec'
2
2
  require 'rails'
3
+ require 'active_record'
3
4
  require 'systematize'
4
5
  require 'pry'
5
6
 
7
+ DATABASE_SPEC_FILE = 'spec/support/db/test.sqlite3'
8
+
6
9
  RSpec.configure do |config|
7
10
  config.color = true
8
11
  config.tty = true
12
+
13
+ config.before(:suite) {
14
+ ActiveRecord::Base.establish_connection(
15
+ adapter: 'sqlite3',
16
+ database: DATABASE_SPEC_FILE,
17
+ )
18
+ }
19
+
20
+ config.after(:suite) {
21
+ FileUtils.rm(DATABASE_SPEC_FILE)
22
+ ActiveRecord::Base.connection.close
23
+ }
9
24
  end
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: ../../../systematize
3
3
  specs:
4
- systematize (0.0.1)
5
- activerecord
6
- railties
4
+ systematize (0.0.2)
5
+ activerecord (>= 3.2)
6
+ railties (>= 3.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -45,6 +45,7 @@ GEM
45
45
  coffee-script-source
46
46
  execjs
47
47
  coffee-script-source (1.10.0)
48
+ diff-lcs (1.3)
48
49
  erubis (2.7.0)
49
50
  execjs (2.7.0)
50
51
  hike (1.2.3)
@@ -91,6 +92,19 @@ GEM
91
92
  rake (11.3.0)
92
93
  rdoc (3.12.2)
93
94
  json (~> 1.4)
95
+ rspec (3.5.0)
96
+ rspec-core (~> 3.5.0)
97
+ rspec-expectations (~> 3.5.0)
98
+ rspec-mocks (~> 3.5.0)
99
+ rspec-core (3.5.4)
100
+ rspec-support (~> 3.5.0)
101
+ rspec-expectations (3.5.0)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.5.0)
104
+ rspec-mocks (3.5.0)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.5.0)
107
+ rspec-support (3.5.0)
94
108
  sass (3.4.22)
95
109
  sass-rails (3.2.6)
96
110
  railties (~> 3.2.0)
@@ -119,6 +133,7 @@ DEPENDENCIES
119
133
  jquery-rails
120
134
  pry
121
135
  rails (= 3.2.0)
136
+ rspec
122
137
  sass-rails (~> 3.2.3)
123
138
  sqlite3
124
139
  systematize!
Binary file
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20161117152655) do
15
+
16
+ create_table "posts", :force => true do |t|
17
+ t.string "title"
18
+ t.string "description"
19
+ t.integer "owner_id"
20
+ t.datetime "created_at", :null => false
21
+ t.datetime "updated_at", :null => false
22
+ t.time "deleted_at"
23
+ end
24
+
25
+ end
@@ -951,3 +951,85 @@ Migrating to AddDeletedAtTimestamp (20161117152138)
951
951
   (0.2ms) begin transaction
952
952
   (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
953
953
   (0.1ms) commit transaction
954
+  (0.3ms) select sqlite_version(*)
955
+  (0.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
956
+  (0.1ms) PRAGMA index_list("schema_migrations")
957
+  (0.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
958
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
959
+ Migrating to CreatePostsTable (20161117151622)
960
+  (0.0ms) begin transaction
961
+  (0.3ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
962
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117151622')
963
+  (0.7ms) commit transaction
964
+ Migrating to AddDeletedAtTimestamp (20161117152138)
965
+  (0.0ms) begin transaction
966
+  (0.3ms) ALTER TABLE "posts" ADD "deleted_at" time
967
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152138')
968
+  (0.6ms) commit transaction
969
+ Migrating to RemoveDeletedColumn (20161117152655)
970
+  (0.0ms) begin transaction
971
+  (0.3ms) CREATE TEMPORARY TABLE "altered_posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
972
+  (0.0ms) PRAGMA index_list("posts")
973
+  (0.0ms) SELECT * FROM "posts"
974
+  (0.2ms) DROP TABLE "posts"
975
+  (0.1ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
976
+  (0.0ms) PRAGMA index_list("altered_posts")
977
+  (0.1ms) SELECT * FROM "altered_posts"
978
+  (0.2ms) DROP TABLE "altered_posts"
979
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152655')
980
+  (0.8ms) commit transaction
981
+  (0.2ms) select sqlite_version(*)
982
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
983
+  (0.0ms) PRAGMA index_list("posts")
984
+  (0.2ms) begin transaction
985
+  (0.1ms) select sqlite_version(*)
986
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
987
+  (0.0ms) PRAGMA index_list("schema_migrations")
988
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
989
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
990
+ Migrating to CreatePostsTable (20161117151622)
991
+  (0.3ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
992
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117151622')
993
+ Migrating to AddDeletedAtTimestamp (20161117152138)
994
+  (0.2ms) ALTER TABLE "posts" ADD "deleted_at" time
995
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152138')
996
+ Migrating to MarkDeletedPostsWithTimestamp (20161117152453)
997
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."deleted" = 't'
998
+  (0.0ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152453')
999
+ Migrating to RemoveDeletedColumn (20161117152655)
1000
+  (0.4ms) CREATE TEMPORARY TABLE "altered_posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
1001
+  (0.0ms) PRAGMA index_list("posts")
1002
+  (0.0ms) SELECT * FROM "posts"
1003
+  (0.1ms) DROP TABLE "posts"
1004
+  (0.1ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
1005
+  (0.0ms) PRAGMA index_list("altered_posts")
1006
+  (0.0ms) SELECT * FROM "altered_posts"
1007
+  (0.2ms) DROP TABLE "altered_posts"
1008
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152655')
1009
+  (1.1ms) commit transaction
1010
+  (0.2ms) begin transaction
1011
+  (0.0ms) select sqlite_version(*)
1012
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
1013
+  (0.0ms) PRAGMA index_list("schema_migrations")
1014
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1015
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
1016
+ Migrating to CreatePostsTable (20161117151622)
1017
+  (0.1ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
1018
+  (0.0ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117151622')
1019
+ Migrating to AddDeletedAtTimestamp (20161117152138)
1020
+  (0.2ms) ALTER TABLE "posts" ADD "deleted_at" time
1021
+  (0.0ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152138')
1022
+ Migrating to MarkDeletedPostsWithTimestamp (20161117152453)
1023
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."deleted" = 't'
1024
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152453')
1025
+ Migrating to RemoveDeletedColumn (20161117152655)
1026
+  (0.3ms) CREATE TEMPORARY TABLE "altered_posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "deleted" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
1027
+  (0.0ms) PRAGMA index_list("posts")
1028
+  (0.0ms) SELECT * FROM "posts"
1029
+  (0.1ms) DROP TABLE "posts"
1030
+  (0.1ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "owner_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" time) 
1031
+  (0.0ms) PRAGMA index_list("altered_posts")
1032
+  (0.0ms) SELECT * FROM "altered_posts"
1033
+  (0.3ms) DROP TABLE "altered_posts"
1034
+  (0.0ms) INSERT INTO "schema_migrations" ("version") VALUES ('20161117152655')
1035
+  (1.9ms) commit transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: systematize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Brazรฃo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-25 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
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'
69
83
  description: Systematize will order your data and struture migrations so you don't
70
84
  have to think which one to run first.
71
85
  email:
@@ -118,8 +132,8 @@ files:
118
132
  - spec/testapp/db/migrate/20161117151622_create_posts_table.rb
119
133
  - spec/testapp/db/migrate/20161117152138_add_deleted_at_timestamp.rb
120
134
  - spec/testapp/db/migrate/20161117152655_remove_deleted_column.rb
135
+ - spec/testapp/db/schema.rb
121
136
  - spec/testapp/db/seeds.rb
122
- - spec/testapp/db/test.sqlite3
123
137
  - spec/testapp/doc/README_FOR_APP
124
138
  - spec/testapp/log/development.log
125
139
  - spec/testapp/public/404.html
@@ -190,8 +204,8 @@ test_files:
190
204
  - spec/testapp/db/migrate/20161117151622_create_posts_table.rb
191
205
  - spec/testapp/db/migrate/20161117152138_add_deleted_at_timestamp.rb
192
206
  - spec/testapp/db/migrate/20161117152655_remove_deleted_column.rb
207
+ - spec/testapp/db/schema.rb
193
208
  - spec/testapp/db/seeds.rb
194
- - spec/testapp/db/test.sqlite3
195
209
  - spec/testapp/doc/README_FOR_APP
196
210
  - spec/testapp/Gemfile
197
211
  - spec/testapp/Gemfile.lock
File without changes