schema_plus 2.0.0.pre8 → 2.0.0.pre9

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: 0f841ad3a38cc1fc65ca2ddf36fdd44568165445
4
- data.tar.gz: bc199b47eb9924938016e662d9c060417fa817ba
3
+ metadata.gz: 61e2c68d4c34a1a67e9dd384a88b39a1c51ac28b
4
+ data.tar.gz: 2d6b58497e571c08e38ce563a74f56b5d1f9a5d3
5
5
  SHA512:
6
- metadata.gz: 0b081af031147830bde1beba8c2481ec9c987b8d8d529b1383cf234e900bfec973ef9adfa5123df5d919975da4a91ef3680fc8553874698b0cb7830bbfc64933
7
- data.tar.gz: 91e463eea4332315156e6a1444f5b599f496f72211c2b907191f749b3c4b0e19283759d643c649e023de7d19b6699a54ea8e276273ac2433e9a34f78bc4f0d3c
6
+ metadata.gz: 70b083aec779efb9afebd741e24ef825d99f0c4dfdd89e416cd3cd4d61f38238a40541e8182dae1de155a96cb5abdd71082666024c145600b391dfc5169cbea5
7
+ data.tar.gz: fa3810d8ba0c11444928631f3d285303c76f1b8bfe272c495cdf82bff2e84285253159d3e51a34c861f0d4adfed5e922fc67ef65eead4b682d83d6397600e97d
data/README.md CHANGED
@@ -20,7 +20,7 @@ Gem | Description | Included In `schema_plus` gem?
20
20
  [schema_plus_columns](https://github.com/SchemaPlus/schema_plus_columns) | Column attributes including `column.indexes` and `column.unique?` | Y
21
21
  <p style="color:grey">schema_plus_db_default</p> | Use `ActiveRecord::DB_DEFAULT` to set an attribute to the database default | Y
22
22
  <p style="color:grey">schema_plus_default_expr</p> | Use SQL expressions for database default values | Y
23
- <p style="color:grey">schema_plus_enums</p> | Use enum types in migrations | Y
23
+ [schema_plus_enums](https://github.com/SchemaPlus/schema_plus_enums) | Define enum types in migrations | Y
24
24
  <p style="color:grey">schema_plus_foreign_keys | Extended support for foreign keys, including creation as column options, `:deferrable`, and SQLite3 support | Y
25
25
  [schema_plus_indexes](https://github.com/SchemaPlus/schema_plus_indexes) | Convenience and consistency in using indexes | Y
26
26
  [schema_plus_pg_indexes](https://github.com/SchemaPlus/schema_plus_pg_indexes) |PostgreSQL index features: `case_insenstive`, `expression` and `operator_class` | Y
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "2.0.0.pre8"
2
+ VERSION = "2.0.0.pre9"
3
3
  end
data/schema_plus.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency "schema_plus_core", "~> 0.2"
27
27
  gem.add_dependency "schema_monkey", "~> 2.1"
28
28
  gem.add_dependency "schema_plus_columns", "~> 0.1"
29
+ gem.add_dependency "schema_plus_enums", "~> 0.1"
29
30
  gem.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
30
31
  gem.add_dependency "schema_plus_pg_indexes", "~> 0.1", ">= 0.1.3"
31
32
  gem.add_dependency "schema_plus_tables", "~> 0.1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre8
4
+ version: 2.0.0.pre9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-27 00:00:00.000000000 Z
12
+ date: 2015-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: schema_plus_enums
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.1'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.1'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: schema_plus_indexes
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -268,9 +282,6 @@ files:
268
282
  - lib/schema_plus/default_expr/active_record/connection_adapters/postgresql_adapter.rb
269
283
  - lib/schema_plus/default_expr/active_record/connection_adapters/sqlite3_adapter.rb
270
284
  - lib/schema_plus/default_expr/middleware.rb
271
- - lib/schema_plus/enums.rb
272
- - lib/schema_plus/enums/active_record.rb
273
- - lib/schema_plus/enums/middleware.rb
274
285
  - lib/schema_plus/foreign_keys.rb
275
286
  - lib/schema_plus/foreign_keys/active_record/base.rb
276
287
  - lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb
@@ -296,8 +307,6 @@ files:
296
307
  - spec/schema_plus_default_expr/column_default_spec.rb
297
308
  - spec/schema_plus_default_expr/migration_spec.rb
298
309
  - spec/schema_plus_default_expr/schema_dumper_spec.rb
299
- - spec/schema_plus_enums/enum_spec.rb
300
- - spec/schema_plus_enums/schema_dumper_spec.rb
301
310
  - spec/schema_plus_foreign_keys/foreign_key_definition_spec.rb
302
311
  - spec/schema_plus_foreign_keys/foreign_key_spec.rb
303
312
  - spec/schema_plus_foreign_keys/migration_spec.rb
@@ -341,8 +350,6 @@ test_files:
341
350
  - spec/schema_plus_default_expr/column_default_spec.rb
342
351
  - spec/schema_plus_default_expr/migration_spec.rb
343
352
  - spec/schema_plus_default_expr/schema_dumper_spec.rb
344
- - spec/schema_plus_enums/enum_spec.rb
345
- - spec/schema_plus_enums/schema_dumper_spec.rb
346
353
  - spec/schema_plus_foreign_keys/foreign_key_definition_spec.rb
347
354
  - spec/schema_plus_foreign_keys/foreign_key_spec.rb
348
355
  - spec/schema_plus_foreign_keys/migration_spec.rb
@@ -1,6 +0,0 @@
1
- require 'schema_plus/core'
2
-
3
- require_relative 'enums/active_record'
4
- require_relative 'enums/middleware'
5
-
6
- SchemaMonkey.register SchemaPlus::Enums
@@ -1,69 +0,0 @@
1
- module SchemaPlus::Enums
2
- module ActiveRecord
3
- module ConnectionAdapters
4
- module PostgresqlAdapter
5
-
6
- def enums
7
- result = query(<<-SQL)
8
- SELECT
9
- N.nspname AS schema_name,
10
- T.typname AS enum_name,
11
- E.enumlabel AS enum_label,
12
- E.enumsortorder AS enum_sort_order
13
- --array_agg(E.enumlabel ORDER BY enumsortorder) AS labels
14
- FROM pg_type T
15
- JOIN pg_enum E ON E.enumtypid = T.oid
16
- JOIN pg_namespace N ON N.oid = T.typnamespace
17
- ORDER BY 1, 2, 4
18
- SQL
19
-
20
- result.reduce([]) do |res, row|
21
- last = res.last
22
- if last && last[0] == row[0] && last[1] == row[1]
23
- last[2] << row[2]
24
- else
25
- res << (row[0..1] << [row[2]])
26
- end
27
- res
28
- end
29
- end
30
-
31
- def create_enum(name, *values)
32
- options = values.extract_options!
33
- list = values.map { |value| escape_enum_value(value) }
34
- execute "CREATE TYPE #{enum_name(name, options[:schema])} AS ENUM (#{list.join(',')})"
35
- end
36
-
37
- def alter_enum(name, value, options = {})
38
- opts = case
39
- when options[:before] then "BEFORE #{escape_enum_value(options[:before])}"
40
- when options[:after] then "AFTER #{escape_enum_value(options[:after])}"
41
- else
42
- ''
43
- end
44
- execute "ALTER TYPE #{enum_name(name, options[:schema])} ADD VALUE #{escape_enum_value(value)} #{opts}"
45
- end
46
-
47
- def drop_enum(name, options = {})
48
- execute "DROP TYPE #{enum_name(name, options[:schema])}"
49
- end
50
-
51
- private
52
-
53
- def enum_name(name, schema)
54
- [schema || 'public', name].map { |s|
55
- %Q{"#{s}"}
56
- }.join('.')
57
- end
58
-
59
- def escape_enum_value(value)
60
- escaped_value = value.sub("'", "''")
61
- "'#{escaped_value}'"
62
- end
63
-
64
-
65
- end
66
- end
67
- end
68
- end
69
-
@@ -1,22 +0,0 @@
1
- module SchemaPlus::Enums
2
- module Middleware
3
-
4
- module Dumper
5
- module Initial
6
-
7
- module Postgresql
8
-
9
- def after(env)
10
- env.connection.enums.each do |schema, name, values|
11
- params = [name.inspect]
12
- params << values.map(&:inspect).join(', ')
13
- params << ":schema => #{schema.inspect}" if schema != 'public'
14
-
15
- env.initial << "create_enum #{params.join(', ')}"
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def enum_fields(name, schema = 'public')
4
- sql = <<-SQL
5
- SELECT array_to_string(array_agg(E.enumlabel ORDER BY enumsortorder), ' ') AS "values"
6
- FROM pg_enum E
7
- JOIN pg_type T ON E.enumtypid = T.oid
8
- JOIN pg_namespace N ON N.oid = T.typnamespace
9
- WHERE N.nspname = '#{schema}' AND T.typname = '#{name}'
10
- GROUP BY T.oid;
11
- SQL
12
-
13
- data = ActiveRecord::Base.connection.select_all(sql)
14
- return nil if data.empty?
15
- data[0]['values'].split(' ')
16
- end
17
-
18
- describe 'enum', :postgresql => :only do
19
- before(:all) do ActiveRecord::Migration.verbose = false end
20
-
21
- let(:migration) { ActiveRecord::Migration }
22
-
23
- describe 'enums' do
24
- it 'should return all enums' do
25
- begin
26
- migration.execute 'create schema cmyk'
27
- migration.create_enum 'color', 'red', 'green', 'blue'
28
- migration.create_enum 'color', 'cyan', 'magenta', 'yellow', 'black', schema: 'cmyk'
29
-
30
- expect(migration.enums).to match_array [['cmyk', 'color', %w|cyan magenta yellow black|], ['public', 'color', %w|red green blue|]]
31
- ensure
32
- migration.drop_enum 'color'
33
- migration.execute 'drop schema cmyk cascade'
34
- end
35
- end
36
- end
37
-
38
- describe 'create_enum' do
39
- it 'should create enum with given values' do
40
- begin
41
- migration.create_enum 'color', *%w|red green blue|
42
- expect(enum_fields('color')).to eq(%w|red green blue|)
43
- ensure
44
- migration.execute 'DROP TYPE IF EXISTS color'
45
- end
46
- end
47
-
48
- it 'should create enum with schema' do
49
- begin
50
- migration.execute 'CREATE SCHEMA colors'
51
- migration.create_enum 'color', *%|red green blue|, schema: 'colors'
52
- expect(enum_fields('color', 'colors')).to eq(%w|red green blue|)
53
- ensure
54
- migration.execute 'DROP SCHEMA IF EXISTS colors CASCADE'
55
- end
56
- end
57
-
58
- it 'should escape enum value' do
59
- begin
60
- migration.create_enum('names', "O'Neal")
61
- expect(enum_fields('names')).to eq(["O'Neal"])
62
- ensure
63
- migration.execute "DROP TYPE IF EXISTS names"
64
- end
65
- end
66
-
67
- it 'should escape schame name and enum name' do
68
- begin
69
- migration.execute 'CREATE SCHEMA "select"'
70
- migration.create_enum 'where', *%|red green blue|, schema: 'select'
71
- expect(enum_fields('where', 'select')).to eq(%w|red green blue|)
72
- ensure
73
- migration.execute 'DROP SCHEMA IF EXISTS "select" CASCADE'
74
- end
75
- end
76
-
77
- end
78
-
79
- describe 'alter_enum' do
80
- before(:each) do migration.create_enum('color', 'red', 'green', 'blue') end
81
- after(:each) do migration.execute 'DROP TYPE IF EXISTS color' end
82
-
83
- it 'should add new value after all values' do
84
- migration.alter_enum('color', 'magenta')
85
- expect(enum_fields('color')).to eq(%w|red green blue magenta|)
86
- end
87
-
88
- it 'should add new value after existed' do
89
- migration.alter_enum('color', 'magenta', after: 'red')
90
- expect(enum_fields('color')).to eq(%w|red magenta green blue|)
91
- end
92
-
93
- it 'should add new value before existed' do
94
- migration.alter_enum('color', 'magenta', before: 'green')
95
- expect(enum_fields('color')).to eq(%w|red magenta green blue|)
96
- end
97
-
98
- it 'should add new value within given schema' do
99
- begin
100
- migration.execute 'CREATE SCHEMA colors'
101
- migration.create_enum('color', 'red', schema: 'colors')
102
- migration.alter_enum('color', 'green', schema: 'colors')
103
-
104
- expect(enum_fields('color', 'colors')).to eq(%w|red green|)
105
- ensure
106
- migration.execute 'DROP SCHEMA colors CASCADE'
107
- end
108
- end
109
- end
110
-
111
- describe 'drop_enum' do
112
- it 'should drop enum with given name' do
113
- migration.execute "CREATE TYPE color AS ENUM ('red', 'blue')"
114
- expect(enum_fields('color')).to eq(%w|red blue|)
115
- migration.drop_enum('color')
116
-
117
- expect(enum_fields('color')).to be_nil
118
- end
119
-
120
- it 'should drop enum within given name and schema' do
121
- begin
122
- migration.execute "CREATE SCHEMA colors; CREATE TYPE colors.color AS ENUM ('red', 'blue')"
123
- expect(enum_fields('color', 'colors')).to eq(%w|red blue|)
124
- migration.drop_enum('color', schema: 'colors')
125
-
126
- expect(enum_fields('color', 'colors')).to be_nil
127
- ensure
128
- migration.execute "DROP SCHEMA colors CASCADE"
129
- end
130
- end
131
- end
132
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'stringio'
3
-
4
- describe "Schema dump" do
5
-
6
- context 'with enum', :postgresql => :only do
7
- let(:connection) { ActiveRecord::Base.connection }
8
-
9
- it 'should include enum' do
10
- begin
11
- connection.execute "CREATE TYPE color AS ENUM ('red', 'green', 'blue')"
12
- expect(dump_schema).to match(%r{create_enum "color", "red", "green", "blue"})
13
- ensure
14
- connection.execute "DROP TYPE color"
15
- end
16
- end
17
-
18
- it 'should include enum with schema' do
19
- begin
20
- connection.execute "CREATE SCHEMA cmyk; CREATE TYPE cmyk.color AS ENUM ('cyan', 'magenta', 'yellow', 'black')"
21
- expect(dump_schema).to match(%r{create_enum "color", "cyan", "magenta", "yellow", "black", :schema => "cmyk"})
22
- ensure
23
- connection.execute "DROP SCHEMA cmyk CASCADE"
24
- end
25
- end
26
- end
27
-
28
- protected
29
-
30
- def dump_schema(opts={})
31
- stream = StringIO.new
32
- ActiveRecord::SchemaDumper.ignore_tables = Array.wrap(opts[:ignore]) || []
33
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
34
- stream.string
35
- end
36
-
37
- end