ez 1.9.3 → 1.9.4

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
  SHA1:
3
- metadata.gz: 7ac405024955a31e91958c4f679c63a062ec6d7e
4
- data.tar.gz: e57f68f2e1a86b817bb592eac4d014334c512d41
3
+ metadata.gz: 30a484332a168113613431f7bf0c9206d784bc67
4
+ data.tar.gz: 0a85d1d5f6902f451321f860f0576a8ee4a65f62
5
5
  SHA512:
6
- metadata.gz: fa70cc7f7e368952a118ac0c162fb89ae71450589effb6be12917719ae88e2a7831168e36156ada6293b826fed36c0689c937d39b908f38ce936c8fc135bc895
7
- data.tar.gz: a0838f2498ca2683405752c7167edeb1ba8ff2a70b8de12ef5042cc67a04a1d41c7f8bf42c3f3aad91e4774b1ba38ddfcca9f0ab82be409fc0b3399dc713e1d4
6
+ metadata.gz: e812e91ee6e64b30033a35b92ee49d8c20ceca3d63a1f3c5df4eac817317d3ba4f8e7e0e580572f0f55331fcc0b5efebbabb6bb673c7660c1cca896f23d24809
7
+ data.tar.gz: 3f63336649e577a6ca59d06b44a41b947b488205d66367715300c12153e54ae8f60192adc2a81db86bdd88033c0cd7320b15dbf56d167e88f924e754ec96548e
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Easy domain modeling in Rails without migrations.
4
4
 
5
- **Version 1.9.3**
5
+ **Version 1.9.4**
6
6
 
7
7
  *For educational purposes only.*
8
8
 
@@ -48,6 +48,17 @@ Alternatively, you can run `rails db:migrate` to generate these files without ru
48
48
  |controllers|true|Generates one controller per model with 7 empty methods.
49
49
  |views|true|Generates the view folder for each model, with 7 empty views.
50
50
 
51
+ ## Development vs Production
52
+
53
+ Renaming a column in `db/models.yml` appear to the gem as if you dropped
54
+ the old column and created a new column. **You will lose any data you
55
+ had in that column**. Same goes for renaming models: the old table
56
+ will be dropped.
57
+
58
+ In production, this could be catastrophic. Therefore, this gem will
59
+ not delete tables or columns in production, only add tables and add
60
+ columns. This could be problematic but is hopefully the 1% case.
61
+
51
62
 
52
63
  ## Syntax Guide for `db/models.yml`**
53
64
 
@@ -136,12 +147,12 @@ Author
136
147
  ### Migrations
137
148
 
138
149
  This gem is expecting that the student will not use database migrations
139
- to control the schema. However, it is ok to use a combination of migrations
150
+ to control the schema. It is ok to use both migrations
140
151
  and `models.yml`, but be aware of the following:
141
152
 
142
- * If at least one migration file is detected, this gem will stop
143
- removing tables that are removed from `models.yml` since
144
- it's not possible to know if there's a migration for it or not.
153
+ * If at least one migration file is detected, this gem will not
154
+ removing tables that would normally removed via `models.yml` since
155
+ it's not possible to know if the table is supposed to be there or not.
145
156
  * Where possible, it's best to translate a migration required for
146
157
  a third-party gem (say, for Devise) into an entry in models.yml
147
158
  so that everything is managed in one place.
data/lib/ez.rb CHANGED
@@ -2,9 +2,7 @@ require "ez/version"
2
2
  require 'ez/domain_modeler'
3
3
  require 'ez/model'
4
4
  require 'ez/config'
5
- require 'ez/rails_updater'
6
- require 'awesome_print'
7
-
5
+ require 'awesome_print' if (Rails.env.development? || Rails.env.test?)
8
6
  require 'hirb' if (Rails.env.development? || Rails.env.test?)
9
7
 
10
8
  module EZ
@@ -17,7 +15,7 @@ module EZ
17
15
  end
18
16
 
19
17
  console do |app|
20
- AwesomePrint.irb!
18
+ AwesomePrint.irb! if (Rails.env.development? || Rails.env.test?)
21
19
 
22
20
  Hirb.enable(pager: false) if (Rails.env.development? || Rails.env.test?) && defined?(Hirb)
23
21
 
@@ -1,4 +1,5 @@
1
1
  require_relative 'schema_modifier'
2
+ require_relative 'rails_updater'
2
3
 
3
4
  module EZ
4
5
 
@@ -20,16 +21,21 @@ module EZ
20
21
  tables.map { |t| t.classify }
21
22
  end
22
23
 
24
+ def self.should_migrate?(models_yml)
25
+ schema_rb = File.join(Rails.root, 'db', 'schema.rb')
26
+ !(Rails.env.development? || Rails.env.test?) ||
27
+ (!File.exist?(schema_rb)) ||
28
+ (File.mtime(schema_rb) < File.mtime(models_yml))
29
+ end
30
+
23
31
  def self.automigrate
24
32
  return unless EZ::Config.models?
25
33
 
26
34
  begin
27
35
  models_yml = File.join(Rails.root, 'db', 'models.yml')
28
- schema_rb = File.join(Rails.root, 'db', 'schema.rb')
29
-
30
36
  EZ::DomainModeler.generate_models_yml unless File.exist?(models_yml)
31
37
 
32
- if !File.exist?(schema_rb) || (File.mtime(schema_rb) < File.mtime(models_yml))
38
+ if should_migrate?(models_yml)
33
39
  old_level = ActiveRecord::Base.logger.level
34
40
 
35
41
  ActiveRecord::Base.logger.level = Logger::WARN
@@ -37,7 +43,7 @@ module EZ
37
43
  dump_schema if (Rails.env.development? || Rails.env.test?)
38
44
 
39
45
  ActiveRecord::Base.logger.level = old_level
40
- EZ::RailsUpdater.update!
46
+ EZ::RailsUpdater.update! if Rails.env.development?
41
47
  end
42
48
  rescue => e
43
49
  puts "Exception: #{e}"
@@ -65,6 +71,8 @@ module EZ
65
71
  end
66
72
 
67
73
  def self.generate_models_yml
74
+ return unless Rails.env.development?
75
+
68
76
  filename = Rails.root + "db/models.yml"
69
77
  unless File.exist?(filename)
70
78
  File.open(filename, "w") do |f|
@@ -8,6 +8,8 @@ module EZ
8
8
  VIEWS = %w(index show destroy new create edit update)
9
9
 
10
10
  def self.update!
11
+ return unless Rails.env.development?
12
+
11
13
  EZ::DomainModeler.tables.each do |table|
12
14
  create_controller(table) if EZ::Config.controllers?
13
15
  create_view_folder(table) if EZ::Config.views?
@@ -16,6 +18,8 @@ module EZ
16
18
  end
17
19
 
18
20
  def self.create_routes(table)
21
+ return unless Rails.env.development?
22
+
19
23
  filename = File.join(Rails.root, 'config', 'routes.rb')
20
24
  line = " resources :#{table}"
21
25
  routes = File.read(filename)
@@ -28,6 +32,8 @@ module EZ
28
32
  end
29
33
 
30
34
  def self.create_controller(controller)
35
+ return unless Rails.env.development?
36
+
31
37
  filename = File.join(Rails.root, 'app', 'controllers', "#{controller}_controller.rb")
32
38
  if !File.exist?(filename)
33
39
  File.open(filename, "w:utf-8") do |file|
@@ -45,6 +51,8 @@ module EZ
45
51
  end
46
52
 
47
53
  def self.create_view_folder(folder)
54
+ return unless Rails.env.development?
55
+
48
56
  full_path = File.join(Rails.root, 'app', 'views', folder)
49
57
  FileUtils.mkdir_p(full_path)
50
58
  VIEWS.each do |view|
@@ -137,6 +137,7 @@ module EZ
137
137
 
138
138
  def remove_dead_schema
139
139
  return unless Rails.env.development? || Rails.env.test?
140
+ return if Dir[File.join(Rails.root, 'db/migrate/*.rb')].entries.any?
140
141
 
141
142
  remove_dead_tables
142
143
  remove_dead_columns
@@ -1,3 +1,3 @@
1
1
  module EZ
2
- VERSION = "1.9.3"
2
+ VERSION = "1.9.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Cohen