dbview_cti 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +15 -0
- data/Gemfile +6 -1
- data/dbview_cti.gemspec +0 -1
- data/lib/db_view_cti/connection_adapters/schema_statements.rb +5 -0
- data/lib/db_view_cti/loader.rb +4 -0
- data/lib/db_view_cti/schema_dumper.rb +45 -0
- data/lib/db_view_cti/version.rb +1 -1
- data/lib/dbview_cti.rb +1 -0
- data/migrate_down.rb +13 -0
- data/migrate_up.rb +10 -0
- data/spec/dummy-rails-4/config/application.rb +3 -0
- metadata +8 -22
- data/spec/dummy-rails-3/db/schema.rb +0 -74
- data/spec/dummy-rails-4/db/schema.rb +0 -74
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- rbx-19mode
|
6
|
+
env:
|
7
|
+
- "RAILS_VERSION=3.2.0"
|
8
|
+
- "RAILS_VERSION=4.0.0"
|
9
|
+
script: bundle exec rspec spec
|
10
|
+
before_script:
|
11
|
+
- psql -c "CREATE USER cti WITH ENCRYPTED PASSWORD 'cti';" -U postgres
|
12
|
+
- psql -c "CREATE DATABASE dbview_cti_test WITH OWNER cti;" -U postgres
|
13
|
+
- ruby ./migrate_up.rb
|
14
|
+
after_success_script:
|
15
|
+
- ruby ./migrate_down.rb
|
data/Gemfile
CHANGED
@@ -28,4 +28,9 @@ else
|
|
28
28
|
"~> #{rails_version}"
|
29
29
|
end
|
30
30
|
|
31
|
-
gem "rails", rails
|
31
|
+
gem "rails", rails
|
32
|
+
|
33
|
+
group :test, :development do
|
34
|
+
gem "activerecord-postgresql-adapter", :platforms => [:ruby, :mswin, :mingw]
|
35
|
+
gem "activerecord-jdbcpostgresql-adapter", :platforms => [:jruby]
|
36
|
+
end
|
data/dbview_cti.gemspec
CHANGED
@@ -25,6 +25,11 @@ module DBViewCTI
|
|
25
25
|
yield # perform table changes in block (e.g. add column)
|
26
26
|
# recreate views in forward order
|
27
27
|
classes.each do |kklass|
|
28
|
+
# any column changes are reflected in the real table cache, but not in the
|
29
|
+
# view cache, so we have to make sure it is cleared
|
30
|
+
true_klass = kklass.constantize
|
31
|
+
true_klass.connection.schema_cache.clear_table_cache!(true_klass.table_name)
|
32
|
+
true_klass.reset_column_information
|
28
33
|
cti_create_view(kklass, options)
|
29
34
|
end
|
30
35
|
end
|
data/lib/db_view_cti/loader.rb
CHANGED
@@ -5,6 +5,10 @@ module DBViewCTI
|
|
5
5
|
include DBViewCTI::ConnectionAdapters::SchemaStatements
|
6
6
|
end
|
7
7
|
|
8
|
+
ActiveRecord::SchemaDumper.class_eval do
|
9
|
+
include DBViewCTI::SchemaDumper
|
10
|
+
end
|
11
|
+
|
8
12
|
if defined?(ActiveRecord::Migration::CommandRecorder)
|
9
13
|
ActiveRecord::Migration::CommandRecorder.class_eval do
|
10
14
|
include DBViewCTI::Migration::CommandRecorder
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# this file is inspired by schema_dumper.rb in the foreigner gem
|
2
|
+
# ( https://github.com/matthuhiggins/foreigner )
|
3
|
+
module DBViewCTI
|
4
|
+
module SchemaDumper
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
alias_method_chain :tables, :cti_views
|
9
|
+
end
|
10
|
+
|
11
|
+
def tables_with_cti_views(stream)
|
12
|
+
tables_without_cti_views(stream)
|
13
|
+
base_classes = []
|
14
|
+
@connection.tables.sort.each do |table|
|
15
|
+
next if ignore_table?(table)
|
16
|
+
klass = DBViewCTI::Names.table_to_class_name(table).constantize
|
17
|
+
base_classes << klass if klass.respond_to?('cti_base_class?') && klass.cti_base_class?
|
18
|
+
end
|
19
|
+
base_classes.each do |klass|
|
20
|
+
dump_cti_hierarchy(klass, stream)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def ignore_table?(table)
|
27
|
+
['schema_migrations', ignore_tables].flatten.any? do |ignored|
|
28
|
+
case ignored
|
29
|
+
when String; table == ignored
|
30
|
+
when Regexp; table =~ ignored
|
31
|
+
else
|
32
|
+
raise StandardError, 'ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def dump_cti_hierarchy(base_class, stream)
|
38
|
+
base_class.cti_all_descendants.each do |class_name|
|
39
|
+
stream.puts(" cti_create_view('#{class_name}')")
|
40
|
+
end
|
41
|
+
stream.puts('')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/db_view_cti/version.rb
CHANGED
data/lib/dbview_cti.rb
CHANGED
data/migrate_down.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Small script to roll back migrations (mainly for use in Travis CI)
|
2
|
+
# (we do this to make sure 'rake db:rollback' is also tested)
|
3
|
+
|
4
|
+
# set correct rails version
|
5
|
+
rails_major_version = 3
|
6
|
+
rails_major_version = ENV["RAILS_VERSION"][0] unless ENV["RAILS_VERSION"].nil?
|
7
|
+
|
8
|
+
# switch to dummy-app for rails version and run migrations
|
9
|
+
Dir.chdir("./spec/dummy-rails-#{rails_major_version}") do
|
10
|
+
1.upto(Dir.glob('./db/migrate/*.rb').length) do
|
11
|
+
system "bundle exec rake db:rollback"
|
12
|
+
end
|
13
|
+
end
|
data/migrate_up.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Small script to run migrations (mainly for use in Travis CI)
|
2
|
+
|
3
|
+
# set correct rails version
|
4
|
+
rails_major_version = 3
|
5
|
+
rails_major_version = ENV["RAILS_VERSION"][0] unless ENV["RAILS_VERSION"].nil?
|
6
|
+
|
7
|
+
# switch to dummy-app for rails version and run migrations
|
8
|
+
Dir.chdir("./spec/dummy-rails-#{rails_major_version}") do
|
9
|
+
system "bundle exec rake db:migrate"
|
10
|
+
end
|
@@ -10,6 +10,9 @@ require "sprockets/railtie"
|
|
10
10
|
Bundler.require(*Rails.groups)
|
11
11
|
require "dbview_cti"
|
12
12
|
|
13
|
+
# for some strange reason, we have to manually require foreigner, it doesn't work through the gemspec file
|
14
|
+
require 'foreigner'
|
15
|
+
|
13
16
|
module Dummy
|
14
17
|
class Application < Rails::Application
|
15
18
|
# Settings in config/environments/* take precedence over those specified here.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbview_cti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: activerecord-postgresql-adapter
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: foreigner
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +68,7 @@ extensions: []
|
|
84
68
|
extra_rdoc_files: []
|
85
69
|
files:
|
86
70
|
- .gitignore
|
71
|
+
- .travis.yml
|
87
72
|
- Gemfile
|
88
73
|
- MIT-LICENSE
|
89
74
|
- README.md
|
@@ -96,6 +81,7 @@ files:
|
|
96
81
|
- lib/db_view_cti/model/extensions.rb
|
97
82
|
- lib/db_view_cti/names.rb
|
98
83
|
- lib/db_view_cti/railtie.rb
|
84
|
+
- lib/db_view_cti/schema_dumper.rb
|
99
85
|
- lib/db_view_cti/sql_generation/migration/base.rb
|
100
86
|
- lib/db_view_cti/sql_generation/migration/factory.rb
|
101
87
|
- lib/db_view_cti/sql_generation/migration/postgresql.rb
|
@@ -103,6 +89,8 @@ files:
|
|
103
89
|
- lib/db_view_cti/version.rb
|
104
90
|
- lib/dbview_cti.rb
|
105
91
|
- lib/tasks/view-based-cti_tasks.rake
|
92
|
+
- migrate_down.rb
|
93
|
+
- migrate_up.rb
|
106
94
|
- spec/dummy-rails-3/.rspec
|
107
95
|
- spec/dummy-rails-3/Rakefile
|
108
96
|
- spec/dummy-rails-3/app/assets/javascripts/application.js
|
@@ -144,7 +132,6 @@ files:
|
|
144
132
|
- spec/dummy-rails-3/db/migrate/20130817014120_create_space_shuttles.rb
|
145
133
|
- spec/dummy-rails-3/db/migrate/20130817024220_create_rocket_engines.rb
|
146
134
|
- spec/dummy-rails-3/db/migrate/20130819040414_add_reliability_to_space_ships.rb
|
147
|
-
- spec/dummy-rails-3/db/schema.rb
|
148
135
|
- spec/dummy-rails-3/lib/assets/.gitkeep
|
149
136
|
- spec/dummy-rails-3/log/.gitkeep
|
150
137
|
- spec/dummy-rails-3/public/404.html
|
@@ -183,7 +170,6 @@ files:
|
|
183
170
|
- spec/dummy-rails-4/config/initializers/wrap_parameters.rb
|
184
171
|
- spec/dummy-rails-4/config/locales/en.yml
|
185
172
|
- spec/dummy-rails-4/config/routes.rb
|
186
|
-
- spec/dummy-rails-4/db/schema.rb
|
187
173
|
- spec/dummy-rails-4/lib/assets/.keep
|
188
174
|
- spec/dummy-rails-4/log/.keep
|
189
175
|
- spec/dummy-rails-4/public/404.html
|
@@ -209,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
195
|
version: '0'
|
210
196
|
segments:
|
211
197
|
- 0
|
212
|
-
hash: -
|
198
|
+
hash: -3953511305276262662
|
213
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
200
|
none: false
|
215
201
|
requirements:
|
@@ -218,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
204
|
version: '0'
|
219
205
|
segments:
|
220
206
|
- 0
|
221
|
-
hash: -
|
207
|
+
hash: -3953511305276262662
|
222
208
|
requirements: []
|
223
209
|
rubyforge_project:
|
224
210
|
rubygems_version: 1.8.25
|
@@ -1,74 +0,0 @@
|
|
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 => 20130819040414) do
|
15
|
-
|
16
|
-
create_table "cars", :force => true do |t|
|
17
|
-
t.integer "motor_vehicle_id"
|
18
|
-
t.boolean "stick_shift"
|
19
|
-
t.boolean "convertible"
|
20
|
-
t.datetime "created_at", :null => false
|
21
|
-
t.datetime "updated_at", :null => false
|
22
|
-
end
|
23
|
-
|
24
|
-
create_table "motor_cycles", :force => true do |t|
|
25
|
-
t.integer "motor_vehicle_id"
|
26
|
-
t.boolean "offroad"
|
27
|
-
t.datetime "created_at", :null => false
|
28
|
-
t.datetime "updated_at", :null => false
|
29
|
-
end
|
30
|
-
|
31
|
-
create_table "motor_vehicles", :force => true do |t|
|
32
|
-
t.integer "vehicle_id"
|
33
|
-
t.string "fuel"
|
34
|
-
t.integer "number_of_wheels"
|
35
|
-
t.datetime "created_at", :null => false
|
36
|
-
t.datetime "updated_at", :null => false
|
37
|
-
end
|
38
|
-
|
39
|
-
create_table "rocket_engines", :force => true do |t|
|
40
|
-
t.integer "space_ship_id"
|
41
|
-
t.string "name"
|
42
|
-
t.datetime "created_at", :null => false
|
43
|
-
t.datetime "updated_at", :null => false
|
44
|
-
end
|
45
|
-
|
46
|
-
create_table "space_ships", :force => true do |t|
|
47
|
-
t.integer "vehicle_id"
|
48
|
-
t.boolean "single_use"
|
49
|
-
t.datetime "created_at", :null => false
|
50
|
-
t.datetime "updated_at", :null => false
|
51
|
-
t.integer "reliability"
|
52
|
-
end
|
53
|
-
|
54
|
-
create_table "space_shuttles", :force => true do |t|
|
55
|
-
t.integer "space_ship_id"
|
56
|
-
t.integer "power"
|
57
|
-
t.datetime "created_at", :null => false
|
58
|
-
t.datetime "updated_at", :null => false
|
59
|
-
end
|
60
|
-
|
61
|
-
create_table "vehicles", :force => true do |t|
|
62
|
-
t.string "name"
|
63
|
-
t.integer "mass"
|
64
|
-
t.datetime "created_at", :null => false
|
65
|
-
t.datetime "updated_at", :null => false
|
66
|
-
end
|
67
|
-
|
68
|
-
add_foreign_key "rocket_engines", "space_ships", :name => "rocket_engines_space_ship_id_fk"
|
69
|
-
|
70
|
-
add_foreign_key "space_ships", "vehicles", :name => "space_ships_vehicle_id_fk"
|
71
|
-
|
72
|
-
add_foreign_key "space_shuttles", "space_ships", :name => "space_shuttles_space_ship_id_fk"
|
73
|
-
|
74
|
-
end
|
@@ -1,74 +0,0 @@
|
|
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 that you check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(version: 20130819040414) do
|
15
|
-
|
16
|
-
create_table "cars", force: true do |t|
|
17
|
-
t.integer "motor_vehicle_id"
|
18
|
-
t.boolean "stick_shift"
|
19
|
-
t.boolean "convertible"
|
20
|
-
t.datetime "created_at"
|
21
|
-
t.datetime "updated_at"
|
22
|
-
end
|
23
|
-
|
24
|
-
create_table "motor_cycles", force: true do |t|
|
25
|
-
t.integer "motor_vehicle_id"
|
26
|
-
t.boolean "offroad"
|
27
|
-
t.datetime "created_at"
|
28
|
-
t.datetime "updated_at"
|
29
|
-
end
|
30
|
-
|
31
|
-
create_table "motor_vehicles", force: true do |t|
|
32
|
-
t.integer "vehicle_id"
|
33
|
-
t.string "fuel"
|
34
|
-
t.integer "number_of_wheels"
|
35
|
-
t.datetime "created_at"
|
36
|
-
t.datetime "updated_at"
|
37
|
-
end
|
38
|
-
|
39
|
-
create_table "rocket_engines", force: true do |t|
|
40
|
-
t.integer "space_ship_id"
|
41
|
-
t.string "name"
|
42
|
-
t.datetime "created_at"
|
43
|
-
t.datetime "updated_at"
|
44
|
-
end
|
45
|
-
|
46
|
-
create_table "space_ships", force: true do |t|
|
47
|
-
t.integer "vehicle_id"
|
48
|
-
t.boolean "single_use"
|
49
|
-
t.datetime "created_at"
|
50
|
-
t.datetime "updated_at"
|
51
|
-
t.integer "reliability"
|
52
|
-
end
|
53
|
-
|
54
|
-
create_table "space_shuttles", force: true do |t|
|
55
|
-
t.integer "space_ship_id"
|
56
|
-
t.integer "power"
|
57
|
-
t.datetime "created_at"
|
58
|
-
t.datetime "updated_at"
|
59
|
-
end
|
60
|
-
|
61
|
-
create_table "vehicles", force: true do |t|
|
62
|
-
t.string "name"
|
63
|
-
t.integer "mass"
|
64
|
-
t.datetime "created_at"
|
65
|
-
t.datetime "updated_at"
|
66
|
-
end
|
67
|
-
|
68
|
-
add_foreign_key "rocket_engines", "space_ships", :name => "rocket_engines_space_ship_id_fk"
|
69
|
-
|
70
|
-
add_foreign_key "space_ships", "vehicles", :name => "space_ships_vehicle_id_fk"
|
71
|
-
|
72
|
-
add_foreign_key "space_shuttles", "space_ships", :name => "space_shuttles_space_ship_id_fk"
|
73
|
-
|
74
|
-
end
|