schema_plus_multischema 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +16 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +141 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.base +4 -0
- data/gemfiles/activerecord-4.2/Gemfile.base +3 -0
- data/gemfiles/activerecord-4.2/Gemfile.postgresql +10 -0
- data/lib/schema_plus_multischema.rb +6 -0
- data/lib/schema_plus_multischema/middleware.rb +45 -0
- data/lib/schema_plus_multischema/version.rb +3 -0
- data/schema_dev.yml +6 -0
- data/schema_plus_multischema.gemspec +30 -0
- data/spec/schema_dumper_spec.rb +75 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/schema.rb +29 -0
- data/spec/tables_spec.rb +53 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71548a7ac7dfe864c8e8b9fb8b650dd92c08e2bf
|
4
|
+
data.tar.gz: 107f3b5e5f90cbc9cdb60636b2cacd256782e043
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f407932d0e10e77f28654fcb8ebe5b9f6284f25d1cf54a040a813b4f73a223f2fa023cae51407ef2dabc5ea370db933de921aed740b7f3efead2eb2fbab281b6
|
7
|
+
data.tar.gz: cc1f3f5ea15e11a5cf20fe46db493970a57f2cdb28a3cc5b594c0bbb3a58b0b131f3ea25123d5b5ec78088701affcf89592f711cc6d6523feb2f409185f6c9d7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
+
# ./schema_dev.yml
|
3
|
+
# Please do not edit this file; any changes will be overwritten next time
|
4
|
+
# schema_dev gets run.
|
5
|
+
---
|
6
|
+
sudo: false
|
7
|
+
rvm:
|
8
|
+
- 2.1.5
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
11
|
+
env: POSTGRESQL_DB_USER=postgres
|
12
|
+
addons:
|
13
|
+
postgresql: '9.4'
|
14
|
+
before_script: bundle exec rake create_databases
|
15
|
+
after_script: bundle exec rake drop_databases
|
16
|
+
script: bundle exec rake travis
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Stenver Jerkku
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/schema_plus_multischema.svg)](http://badge.fury.io/rb/schema_plus_multischema)
|
2
|
+
[![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_multischema.svg)](http://travis-ci.org/SchemaPlus/schema_plus_multischema)
|
3
|
+
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_multischema.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_multischema)
|
4
|
+
|
5
|
+
|
6
|
+
# SchemaPlusMultischema
|
7
|
+
|
8
|
+
SchemaPlusMultischema adds support for using multiple schemas with ActiveRecord. Note that the gem only adds functionality if the database schema search path is not DBMS default (```schema_search_path='$user,public'```).
|
9
|
+
|
10
|
+
Then following features are supported:
|
11
|
+
|
12
|
+
* `ActiveRecord::Connection#tables` returns each table name in the form `"schema.table"`
|
13
|
+
|
14
|
+
* Schema dump includes the schema definitions, search path and creates each table in its appropriate schema. In addition, it all foreign key references will contain table references in its appropriate schema.
|
15
|
+
|
16
|
+
Support is currently limited to Postgresql. See details below.
|
17
|
+
|
18
|
+
SchemaPlusMultischema is part of the [SchemaPlus](https://github.com/SchemaPlus/) family of Ruby on Rails ActiveRecord extension gems.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - begin -->
|
23
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
24
|
+
As usual:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem "schema_plus_multischema" # in a Gemfile
|
28
|
+
gem.add_dependency "schema_plus_multischema" # in a .gemspec
|
29
|
+
```
|
30
|
+
|
31
|
+
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
|
32
|
+
|
33
|
+
## Compatibility
|
34
|
+
|
35
|
+
SchemaPlusMultischema is tested on:
|
36
|
+
|
37
|
+
<!-- SCHEMA_DEV: MATRIX - begin -->
|
38
|
+
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
39
|
+
* ruby **2.1.5** with activerecord **4.2**, using **postgresql**
|
40
|
+
|
41
|
+
<!-- SCHEMA_DEV: MATRIX - end -->
|
42
|
+
|
43
|
+
SchemaPlusMultischema should be a no-op if used with sqlite3 or mysql.
|
44
|
+
|
45
|
+
## Background
|
46
|
+
|
47
|
+
Your PostgreSQL database might have multiple schemas, that provide namespaces for tables. For example, you could define:
|
48
|
+
|
49
|
+
connection.execute "CREATE SCHEMA first"
|
50
|
+
connection.execute "CREATE SCHEMA second"
|
51
|
+
|
52
|
+
ActiveRecord's PostgreSQL connection adapter lets you [set PostgreSQL's search_path](http://apidock.com/rails/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/schema_search_path%3D) to choose which schemas to look at:
|
53
|
+
|
54
|
+
connection.schema_search_path = "first,second"
|
55
|
+
|
56
|
+
And ActiveRecord let you use schema names in migrations, such as
|
57
|
+
|
58
|
+
create_table 'first.my_table' do ...
|
59
|
+
create_table 'second.my_table' do ...
|
60
|
+
|
61
|
+
But without SchemaPlusMultischema, ActiveRecord's introspection doesn't handle them properly. It *does* find all tables that are in the current search path, but it *doesn't* prefix them with their schema names. The schema dump `schema/dump.rb` doesn't take into account the schemas at all and the dump will be invalid. Futhermore, if there are tables with the same name in different schemas, only 1 of the tables will be dumped.
|
62
|
+
|
63
|
+
## Features
|
64
|
+
|
65
|
+
With SchemaPlusMultischema installed, it activates its features whenever your schema search path differs from PostgreSQL's default (```"$user",public```). If schema search path is PostgreSQL's default, then SchemaPlusMultischema stays out of the way and the behavior is the same as pure ActiveRecord.
|
66
|
+
|
67
|
+
### `connection.tables`
|
68
|
+
|
69
|
+
The output of ActiveRecord's `connection.tables` method will have table name prefixed with its schema. E.g.
|
70
|
+
|
71
|
+
connection.tables # => ["first.my_table", "second.my_table"]
|
72
|
+
|
73
|
+
### Schema dump
|
74
|
+
|
75
|
+
The schema dump (`db/schema.rb`) will include the schema setup, and the table definitions will be prefixed with their schemas. E.g.
|
76
|
+
|
77
|
+
connection.execute "CREATE SCHEMA IF NOT EXISTS first"
|
78
|
+
connection.execute "CREATE SCHEMA IF NOT EXISTS second"
|
79
|
+
connection.schema_search_path = "first,second"
|
80
|
+
|
81
|
+
create_table "first.my_table" do ...
|
82
|
+
create_table "second.my_table" do ...
|
83
|
+
|
84
|
+
If you're using the [schema_plus_foreign_keys](https://github.com/SchemaPlus/schema_plus_foreign_keys) gem, foreign key associations will also contain table definitions with prefixed schemas. E.g.
|
85
|
+
|
86
|
+
create_table "first.my_table" do
|
87
|
+
...
|
88
|
+
t.integer :my_table_id, null: false, foreign_key: {references: "second.my_table"...
|
89
|
+
|
90
|
+
|
91
|
+
## History
|
92
|
+
|
93
|
+
* 0.1.0 - Initial release
|
94
|
+
|
95
|
+
## Development & Testing
|
96
|
+
|
97
|
+
Are you interested in contributing to SchemaPlusMultischema? Thanks! Please follow
|
98
|
+
the standard protocol: fork, feature branch, develop, push, and issue pull
|
99
|
+
request.
|
100
|
+
|
101
|
+
Some things to know about to help you develop and test:
|
102
|
+
|
103
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - begin -->
|
104
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
105
|
+
* **schema_dev**: SchemaPlus::Multischema uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
106
|
+
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
107
|
+
versions that the gem supports, both locally and on
|
108
|
+
[travis-ci](http://travis-ci.org/SchemaPlus/schema_plus_multischema)
|
109
|
+
|
110
|
+
To to run rspec locally on the full matrix, do:
|
111
|
+
|
112
|
+
$ schema_dev bundle install
|
113
|
+
$ schema_dev rspec
|
114
|
+
|
115
|
+
You can also run on just one configuration at a time; For info, see `schema_dev --help` or the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
|
116
|
+
|
117
|
+
The matrix of configurations is specified in `schema_dev.yml` in
|
118
|
+
the project root.
|
119
|
+
|
120
|
+
|
121
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
122
|
+
|
123
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
|
124
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
125
|
+
* **schema_plus_core**: SchemaPlus::Multischema uses the SchemaPlus::Core API that
|
126
|
+
provides middleware callback stacks to make it easy to extend
|
127
|
+
ActiveRecord's behavior. If that API is missing something you need for
|
128
|
+
your contribution, please head over to
|
129
|
+
[schema_plus_core](https://github.com/SchemaPlus/schema_plus_core) and open
|
130
|
+
an issue or pull request.
|
131
|
+
|
132
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - end -->
|
133
|
+
|
134
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin -->
|
135
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
136
|
+
* **schema_monkey**: SchemaPlus::Multischema is implemented as a
|
137
|
+
[schema_monkey](https://github.com/SchemaPlus/schema_monkey) client,
|
138
|
+
using [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s
|
139
|
+
convention-based protocols for extending ActiveRecord and using middleware stacks.
|
140
|
+
|
141
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module SchemaPlusMultischema
|
2
|
+
module Middleware
|
3
|
+
|
4
|
+
module PostgreSQL
|
5
|
+
DEFAULT_SCHEMA_SEARCH_PATH = %q{"$user",public}
|
6
|
+
|
7
|
+
module Schema
|
8
|
+
module Tables
|
9
|
+
|
10
|
+
def implement(env)
|
11
|
+
use_prefix = (env.connection.schema_search_path != DEFAULT_SCHEMA_SEARCH_PATH)
|
12
|
+
query = <<-SQL
|
13
|
+
SELECT schemaname, tablename
|
14
|
+
FROM pg_tables
|
15
|
+
WHERE schemaname = ANY(current_schemas(false))
|
16
|
+
SQL
|
17
|
+
env.tables += env.connection.exec_query(query, 'SCHEMA').map { |row|
|
18
|
+
if use_prefix
|
19
|
+
"#{row['schemaname']}.#{row['tablename']}"
|
20
|
+
else
|
21
|
+
row['tablename']
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Dumper
|
30
|
+
module Initial
|
31
|
+
|
32
|
+
def after(env)
|
33
|
+
if (path = env.connection.schema_search_path) != DEFAULT_SCHEMA_SEARCH_PATH
|
34
|
+
path.split(',').each do |name|
|
35
|
+
env.initial << %Q{ connection.execute "CREATE SCHEMA IF NOT EXISTS #{name}"}
|
36
|
+
end
|
37
|
+
env.initial << %Q{ connection.schema_search_path = #{path.inspect}}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/schema_dev.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'schema_plus_multischema/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "schema_plus_multischema"
|
8
|
+
gem.version = SchemaPlusMultischema::VERSION
|
9
|
+
gem.authors = ["Stenver Jerkku"]
|
10
|
+
gem.email = ["stenver1010@gmail.com"]
|
11
|
+
gem.summary = %q{Adds support for multiple schemas in activerecord when using Postgres}
|
12
|
+
gem.homepage = "https://github.com/SchemaPlus/schema_plus_multischema"
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = `git ls-files -z`.split("\x0")
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "activerecord", "~> 4.2"
|
21
|
+
gem.add_dependency "schema_plus_core", "~> 0.5"
|
22
|
+
|
23
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
25
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
gem.add_development_dependency "schema_dev", "~> 3.5", ">= 3.5.1"
|
27
|
+
gem.add_development_dependency "simplecov"
|
28
|
+
gem.add_development_dependency "simplecov-gem-profile"
|
29
|
+
gem.add_development_dependency "schema_plus_foreign_keys"
|
30
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Schema dump' do
|
4
|
+
let(:connection) { ActiveRecord::Base.connection }
|
5
|
+
|
6
|
+
context "with multiple schemas" do
|
7
|
+
|
8
|
+
around(:each) do |example|
|
9
|
+
with_schemas %w[first second] do
|
10
|
+
example.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "includes the schema definitions and path in the dump" do
|
15
|
+
expect(dump_schema).to include('CREATE SCHEMA IF NOT EXISTS first')
|
16
|
+
expect(dump_schema).to include('CREATE SCHEMA IF NOT EXISTS second')
|
17
|
+
expect(dump_schema).to include('schema_search_path = "first,second"')
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a table that is created without a schema prefix' do
|
21
|
+
before(:each) do
|
22
|
+
schema_definitions do
|
23
|
+
create_table 'no_schema_prefix'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
it 'includes schema prefix in dump' do
|
27
|
+
expect(dump_schema).to include('create_table "first.no_schema_prefix"')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'tables with same name in different schemas' do
|
32
|
+
before(:each) do
|
33
|
+
schema_definitions do
|
34
|
+
create_table 'first.dogs'
|
35
|
+
create_table 'second.dogs'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'includes both tables with schema prefixes' do
|
40
|
+
expect(dump_schema).to include('create_table "first.dogs"')
|
41
|
+
expect(dump_schema).to include('create_table "second.dogs"')
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with schema_plus_foreign_keys support' do
|
45
|
+
before(:each) do
|
46
|
+
schema_definitions do
|
47
|
+
create_table 'first.owners' do |t|
|
48
|
+
t.integer :dog_id, null: false, references: 'second.dogs'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'includes foreign key references with schema prefixes' do
|
54
|
+
expect(dump_schema).to include('foreign_key: {references: "second.dogs", name: "fk_first_owners_dog_id"')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "without multiple schemas" do
|
61
|
+
it "does not include schema setup" do
|
62
|
+
expect(dump_schema).not_to include('CREATE SCHEMA')
|
63
|
+
expect(dump_schema).not_to include('schema_search_path')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def dump_schema
|
70
|
+
stream = StringIO.new
|
71
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
72
|
+
stream.string
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-gem-profile'
|
3
|
+
SimpleCov.start "gem"
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
require 'active_record'
|
10
|
+
require 'schema_plus_multischema'
|
11
|
+
require 'schema_dev/rspec'
|
12
|
+
require 'schema_plus_foreign_keys'
|
13
|
+
|
14
|
+
SchemaDev::Rspec.setup
|
15
|
+
|
16
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.warnings = true
|
20
|
+
config.around(:each) do |example|
|
21
|
+
ActiveRecord::Migration.suppress_messages do
|
22
|
+
example.run
|
23
|
+
drop_all_tables
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
SimpleCov.command_name "[ruby#{RUBY_VERSION}-activerecord#{::ActiveRecord.version}-#{ActiveRecord::Base.connection.adapter_name}]"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
def with_schemas(names)
|
2
|
+
connection = ActiveRecord::Base.connection
|
3
|
+
begin
|
4
|
+
previous_schemas = connection.schema_search_path
|
5
|
+
names.each do |name|
|
6
|
+
connection.execute "CREATE SCHEMA IF NOT EXISTS #{name}"
|
7
|
+
end
|
8
|
+
connection.schema_search_path = names.join(',')
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
drop_all_tables
|
12
|
+
names.each do |name|
|
13
|
+
connection.execute "DROP SCHEMA IF EXISTS #{name}"
|
14
|
+
end
|
15
|
+
connection.schema_search_path = previous_schemas
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def schema_definitions(&block)
|
20
|
+
ActiveRecord::Schema.define &block
|
21
|
+
end
|
22
|
+
|
23
|
+
def drop_all_tables
|
24
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
25
|
+
ActiveRecord::Base.connection.drop_table table, force: :cascade
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
data/spec/tables_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'tables' do
|
4
|
+
|
5
|
+
let(:connection) { ActiveRecord::Base.connection }
|
6
|
+
|
7
|
+
context "with multiple schemas" do
|
8
|
+
|
9
|
+
around(:each) do |example|
|
10
|
+
with_schemas %w[first second] do
|
11
|
+
example.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with a table that is created without a schema prefix' do
|
16
|
+
before(:each) do
|
17
|
+
schema_definitions do
|
18
|
+
create_table 'no_schema_prefix'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
it 'includes schema prefix in table name' do
|
22
|
+
expect(connection.tables).to eq %w[first.no_schema_prefix]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with tables with same name in different schemas' do
|
27
|
+
before(:each) do
|
28
|
+
schema_definitions do
|
29
|
+
create_table 'first.dogs'
|
30
|
+
create_table 'second.dogs'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'includes schema prefix in table names' do
|
35
|
+
expect(connection.tables.sort).to eq %w[first.dogs second.dogs]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "without multiple schemas" do
|
42
|
+
before(:each) do
|
43
|
+
schema_definitions do
|
44
|
+
create_table 'dogs'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not include schema_prefix in table names' do
|
49
|
+
expect(connection.tables).to eq %w[dogs]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schema_plus_multischema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stenver Jerkku
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: schema_plus_core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: schema_dev
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 3.5.1
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '3.5'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 3.5.1
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov-gem-profile
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: schema_plus_foreign_keys
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
description:
|
146
|
+
email:
|
147
|
+
- stenver1010@gmail.com
|
148
|
+
executables: []
|
149
|
+
extensions: []
|
150
|
+
extra_rdoc_files: []
|
151
|
+
files:
|
152
|
+
- ".gitignore"
|
153
|
+
- ".travis.yml"
|
154
|
+
- Gemfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- gemfiles/Gemfile.base
|
159
|
+
- gemfiles/activerecord-4.2/Gemfile.base
|
160
|
+
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
161
|
+
- lib/schema_plus_multischema.rb
|
162
|
+
- lib/schema_plus_multischema/middleware.rb
|
163
|
+
- lib/schema_plus_multischema/version.rb
|
164
|
+
- schema_dev.yml
|
165
|
+
- schema_plus_multischema.gemspec
|
166
|
+
- spec/schema_dumper_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/schema.rb
|
169
|
+
- spec/tables_spec.rb
|
170
|
+
homepage: https://github.com/SchemaPlus/schema_plus_multischema
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.2.2
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Adds support for multiple schemas in activerecord when using Postgres
|
194
|
+
test_files:
|
195
|
+
- spec/schema_dumper_spec.rb
|
196
|
+
- spec/spec_helper.rb
|
197
|
+
- spec/support/schema.rb
|
198
|
+
- spec/tables_spec.rb
|