peegee 0 → 0.1
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.
- data/.gitignore +4 -0
- data/CHANGES +10 -0
- data/README.md +41 -0
- data/Rakefile +17 -0
- data/TODO +3 -0
- data/features/create_indexes_in_migrations.feature +87 -6
- data/features/step_definitions/migration_steps.rb +1 -1
- data/features/step_definitions/rails_steps.rb +7 -0
- data/features/support/env.rb +7 -0
- data/features/support/sql_helpers.rb +1 -28
- data/lib/peegee.rb +6 -2
- data/lib/peegee/index.rb +115 -0
- data/lib/peegee/quoting.rb +9 -0
- data/lib/peegee/schema_statement.rb +24 -0
- data/lib/peegee/version.rb +1 -1
- data/peegee.gemspec +4 -3
- data/spec/index_spec.rb +42 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/sql_helpers.rb +45 -0
- metadata +36 -9
- data/Gemfile.lock +0 -118
data/CHANGES
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Version 0.1 - Fri Sep 23 23:29:04 -0400 2011
|
2
|
+
===============================================================================
|
3
|
+
Harold Gimenez and Mike Burns:
|
4
|
+
|
5
|
+
Initial release with support to various index types:
|
6
|
+
|
7
|
+
* Partial indexes
|
8
|
+
* Expression indexes
|
9
|
+
* Sorted indexes
|
10
|
+
* Building indexes concurrently: Since AR migrations are wrapped in a transaction, and concurrent index building cannot be in a transaction, we commit the transaction, issue the CREATE INDEX statement, and start a new transaction afterwards.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## Peegee
|
2
|
+
Peegee aims to bring better support for PostgreSQL to ActiveRecord. Peegee is under active development.
|
3
|
+
|
4
|
+
###Indexes
|
5
|
+
|
6
|
+
Peegee adds support for some indexing extensions allowed by Postgres. You can run these in your migrations.
|
7
|
+
|
8
|
+
#### Partial indexes
|
9
|
+
```ruby
|
10
|
+
add_index :users, :column, :where => 'active = true'
|
11
|
+
```
|
12
|
+
|
13
|
+
#### Expression indexes
|
14
|
+
```ruby
|
15
|
+
add_index :users, :name => 'users_created_at_date' do |i|
|
16
|
+
i.expression 'DATE(created_at)'
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
#### Sorted indexes
|
21
|
+
```ruby
|
22
|
+
add_index :users, :name => 'users_created_at_date' do |i|
|
23
|
+
i.column :name, :asc
|
24
|
+
i.column :active, :desc
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
#### Using [CONCURRENTLY](http://www.postgresql.org/docs/9.0/static/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY)
|
29
|
+
```ruby
|
30
|
+
add_index :users, :name, :name => 'users_name', :concurrently => true
|
31
|
+
```
|
32
|
+
|
33
|
+
*Note* that this cannot run inside of a transaction. This will commit your
|
34
|
+
running transaction, add the index concurrently, and start a new transaction.
|
35
|
+
Use with caution.
|
36
|
+
|
37
|
+
### License
|
38
|
+
|
39
|
+
Peegee is distributed under the MIT license.
|
40
|
+
|
41
|
+
Copyright 2011 - Harold Giménez and Mike Burns
|
data/Rakefile
CHANGED
@@ -1,2 +1,19 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'herodotus/tasks'
|
7
|
+
|
8
|
+
Herodotus::Configuration.run do |config|
|
9
|
+
config.base_path = File.dirname __FILE__
|
10
|
+
config.changelog_filename = 'CHANGES'
|
11
|
+
end
|
12
|
+
|
13
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
14
|
+
t.cucumber_opts = "features --format progress"
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec)
|
18
|
+
|
19
|
+
task :default => [:spec,:features]
|
data/TODO
ADDED
@@ -1,21 +1,102 @@
|
|
1
1
|
Feature: Adding PostgreSQL specific indexes in a Rails migration
|
2
2
|
As a developer
|
3
3
|
I can add PostgreSQL index types in a migration
|
4
|
-
So that
|
4
|
+
So that my application has better performance
|
5
5
|
|
6
|
-
|
6
|
+
Background:
|
7
7
|
Given I create and configure the "peegee_test" rails app
|
8
8
|
And I run `script/rails generate model User name:string active:boolean`
|
9
|
-
|
9
|
+
|
10
|
+
Scenario: Adding a partial index
|
11
|
+
Given I run `script/rails generate migration add_index_to_active_users`
|
10
12
|
And I implement the latest migration as:
|
11
13
|
"""
|
12
14
|
def self.up
|
13
15
|
add_index :users, :name, :name => 'users_name_where_active_true', :where => 'active = true'
|
14
16
|
end
|
15
|
-
|
16
|
-
|
17
|
+
"""
|
18
|
+
And I run `bundle exec rake db:migrate --trace`
|
19
|
+
Then the "users" table should have the following index:
|
20
|
+
| CREATE INDEX users_name_where_active_true ON users USING btree (name) WHERE active = true |
|
21
|
+
|
22
|
+
Scenario: Adding an expression index
|
23
|
+
Given I run `script/rails generate migration add_index_on_date_created_at`
|
24
|
+
And I implement the latest migration as:
|
25
|
+
"""
|
26
|
+
def self.up
|
27
|
+
add_index :users, :name => 'users_created_at_date' do |i|
|
28
|
+
i.expression "DATE(created_at)"
|
29
|
+
end
|
17
30
|
end
|
18
31
|
"""
|
19
32
|
And I run `bundle exec rake db:migrate`
|
20
33
|
Then the "users" table should have the following index:
|
21
|
-
| CREATE INDEX
|
34
|
+
| CREATE INDEX users_created_at_date ON users USING btree (date(created_at)) |
|
35
|
+
|
36
|
+
Scenario: Adding an expression partial index
|
37
|
+
Given I run `script/rails generate migration add_index_on_date_created_at`
|
38
|
+
And I implement the latest migration as:
|
39
|
+
"""
|
40
|
+
def self.up
|
41
|
+
add_index :users, :name => 'users_created_at_date_where_active_true', :where => 'active = true' do |i|
|
42
|
+
i.expression "DATE(created_at)"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
"""
|
46
|
+
And I run `bundle exec rake db:migrate`
|
47
|
+
Then the "users" table should have the following index:
|
48
|
+
| CREATE INDEX users_created_at_date_where_active_true ON users USING btree (date(created_at)) WHERE active = true |
|
49
|
+
|
50
|
+
Scenario: Adding a sort order to an index
|
51
|
+
Given I run `script/rails generate migration add_index_on_users_name_asc`
|
52
|
+
And I implement the latest migration as:
|
53
|
+
"""
|
54
|
+
def self.up
|
55
|
+
add_index :users, :name => 'users_name_asc_active_desc' do |i|
|
56
|
+
i.column :name, :asc
|
57
|
+
i.column :active, :desc
|
58
|
+
end
|
59
|
+
end
|
60
|
+
"""
|
61
|
+
And I run `bundle exec rake db:migrate --trace`
|
62
|
+
Then the "users" table should have the following index:
|
63
|
+
| CREATE INDEX users_name_asc_active_desc ON users USING btree (name, active DESC) |
|
64
|
+
|
65
|
+
Scenario: Adding an index with a sort order but with nulls sorted specifically
|
66
|
+
Given I run `script/rails generate migration add_index_on_users_nulls_sorted`
|
67
|
+
And I implement the latest migration as:
|
68
|
+
"""
|
69
|
+
def self.up
|
70
|
+
add_index :users, :name => 'users_name_asc_active_desc' do |i|
|
71
|
+
i.column :name, :asc, :nulls => :first
|
72
|
+
i.column :active, :desc, :nulls => :last
|
73
|
+
end
|
74
|
+
end
|
75
|
+
"""
|
76
|
+
And I run `bundle exec rake db:migrate --trace`
|
77
|
+
Then the "users" table should have the following index:
|
78
|
+
| CREATE INDEX users_name_asc_active_desc ON users USING btree (name NULLS FIRST, active DESC NULLS LAST) |
|
79
|
+
|
80
|
+
Scenario: Adding a unique index
|
81
|
+
Given I run `script/rails generate migration add_unique_index_to_active_users`
|
82
|
+
And I implement the latest migration as:
|
83
|
+
"""
|
84
|
+
def self.up
|
85
|
+
add_index :users, :name, :name => 'users_name_where_active_true', :where => 'active = true', :unique => true
|
86
|
+
end
|
87
|
+
"""
|
88
|
+
And I run `bundle exec rake db:migrate --trace`
|
89
|
+
Then the "users" table should have the following index:
|
90
|
+
| CREATE UNIQUE INDEX users_name_where_active_true ON users USING btree (name) WHERE active = true |
|
91
|
+
|
92
|
+
Scenario: Adding an index concurrently
|
93
|
+
Given I run `script/rails generate migration add_unique_index_to_active_users`
|
94
|
+
And I implement the latest migration as:
|
95
|
+
"""
|
96
|
+
def self.up
|
97
|
+
add_index :users, :name, :name => 'users_name_concurrent', :concurrently => true
|
98
|
+
end
|
99
|
+
"""
|
100
|
+
And I run `bundle exec rake db:migrate --trace`
|
101
|
+
Then the "users" table should have the following index:
|
102
|
+
| CREATE INDEX users_name_concurrent ON users USING btree (name) |
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Given /^I implement the latest migration as:$/ do |implementation|
|
2
2
|
in_current_dir do
|
3
|
-
migrations = Dir["db/migrate
|
3
|
+
migrations = Dir["db/migrate/[0-9]*_*.rb"].sort.to_a
|
4
4
|
path = migrations.last
|
5
5
|
contents = IO.read(path)
|
6
6
|
class_declaration = contents.split("\n").first
|
@@ -1,3 +1,9 @@
|
|
1
|
+
When /^I add the "([^"]*)" gem from this project as a dependency$/ do |gem_name|
|
2
|
+
in_current_dir do
|
3
|
+
append_to_file('Gemfile', %{\ngem "#{gem_name}", path => #{PROJECT_ROOT}})
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
Given /^I create and configure the "(\w+)" rails app$/ do |name|
|
2
8
|
Given %{I run `rails new #{name} --database=postgresql -J -T -G`}
|
3
9
|
And %{I cd to "peegee_test"}
|
@@ -17,6 +23,7 @@ test:
|
|
17
23
|
in_current_dir do
|
18
24
|
File.open('config/database.yml', 'w') { |file| file.write(database_config) }
|
19
25
|
end
|
26
|
+
And %{I add the "peegee" gem from this project as a dependency}
|
20
27
|
And %{I run `bundle install`}
|
21
28
|
And %{I run `bundle exec rake db:drop:all db:create:all`}
|
22
29
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'aruba/cucumber'
|
2
2
|
require 'ruby-debug'
|
3
3
|
|
4
|
+
PROJECT_ROOT = File.expand_path('../..', File.dirname(__FILE__))
|
5
|
+
|
4
6
|
Before do
|
5
7
|
@aruba_timeout_seconds = 10
|
6
8
|
end
|
9
|
+
|
10
|
+
After do
|
11
|
+
FileUtils.rm_rf(File.join(PROJECT_ROOT, 'tmp', 'aruba', 'peegee_test'))
|
12
|
+
disconnect_test_db
|
13
|
+
end
|
@@ -1,30 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
module SqlHelpers
|
3
|
-
def connection
|
4
|
-
@connection || begin
|
5
|
-
ActiveRecord::Base.establish_connection(
|
6
|
-
:adapter => 'postgresql',
|
7
|
-
:encoding => 'unicode',
|
8
|
-
:database => 'peegee_development'
|
9
|
-
)
|
10
|
-
ActiveRecord::Base.connection
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def select_all(sql)
|
15
|
-
connection.select_all sql
|
16
|
-
end
|
17
|
-
|
18
|
-
def oid(table_name)
|
19
|
-
select_all(<<-SQL).first['oid']
|
20
|
-
SELECT c.oid
|
21
|
-
FROM pg_catalog.pg_class c
|
22
|
-
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
23
|
-
WHERE c.relname = '#{table_name}'
|
24
|
-
AND pg_catalog.pg_table_is_visible(c.oid);
|
25
|
-
SQL
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
1
|
+
require 'spec/support/sql_helpers'
|
29
2
|
|
30
3
|
World(SqlHelpers)
|
data/lib/peegee.rb
CHANGED
data/lib/peegee/index.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module Peegee
|
2
|
+
class Index
|
3
|
+
|
4
|
+
attr_accessor :index_name, :table_name, :options, :uniqueness
|
5
|
+
attr_accessor :columns_or_expressions
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
self.table_name = options[:table_name]
|
9
|
+
self.columns_or_expressions = options.key?(:column) ? [[:column, options[:column], []]] : []
|
10
|
+
self.options = options[:options]
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_sql
|
14
|
+
check_index_name_length
|
15
|
+
|
16
|
+
sql = "CREATE #{uniqueness} INDEX #{concurrentliness} #{adapter.quote_column_name(index_name)} ON #{adapter.quote_table_name(table_name)} (#{columns_or_expressions_sql}) #{tablespace_sql}"
|
17
|
+
if @options.key?(:where)
|
18
|
+
sql += " WHERE #{options[:where]}"
|
19
|
+
end
|
20
|
+
|
21
|
+
sql
|
22
|
+
end
|
23
|
+
|
24
|
+
def column(name, *args)
|
25
|
+
columns_or_expressions << [:column, name, args]
|
26
|
+
end
|
27
|
+
|
28
|
+
def expression(expr, *args)
|
29
|
+
columns_or_expressions << [:expression, expr, args]
|
30
|
+
end
|
31
|
+
|
32
|
+
def column=(column)
|
33
|
+
columns_or_expressions << [:column, column, []]
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_outside_transaction?
|
37
|
+
options[:concurrently]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def columns_or_expressions_sql
|
43
|
+
self.columns_or_expressions.map do |tag,column_or_expression,args|
|
44
|
+
column_or_expression_sql(tag, column_or_expression, args)
|
45
|
+
end.join(', ')
|
46
|
+
end
|
47
|
+
|
48
|
+
def column_or_expression_sql(tag, column_or_expression, args)
|
49
|
+
case tag
|
50
|
+
when :column
|
51
|
+
"#{Peegee::Quoting.quoted_columns_for_index(column_or_expression)} #{column_options_sql(args)}"
|
52
|
+
when :expression
|
53
|
+
column_or_expression
|
54
|
+
else
|
55
|
+
raise RuntimeError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def column_options_sql(options)
|
60
|
+
hash_options = options.last.respond_to?(:key?) ? options.pop : {}
|
61
|
+
|
62
|
+
"#{column_single_options_sql(options)} #{column_hash_options_sql(hash_options)}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def column_single_options_sql(options)
|
66
|
+
options.first.try(:to_s).try(:upcase) || ""
|
67
|
+
end
|
68
|
+
|
69
|
+
def column_hash_options_sql(options)
|
70
|
+
options.inject("") do |acc, (k,v)|
|
71
|
+
"#{k.to_s.upcase} #{v.to_s.upcase} #{acc}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def tablespace_sql
|
76
|
+
self.options[:tablespace] ? "TABLESPACE #{self.options[:tablespace]}" : ""
|
77
|
+
end
|
78
|
+
|
79
|
+
def uniqueness
|
80
|
+
self.options[:unique] ? "UNIQUE" : ""
|
81
|
+
end
|
82
|
+
|
83
|
+
def concurrentliness
|
84
|
+
self.options[:concurrently] ? "CONCURRENTLY" : ""
|
85
|
+
end
|
86
|
+
|
87
|
+
def index_name
|
88
|
+
options[:name] || default_index_name
|
89
|
+
end
|
90
|
+
|
91
|
+
def default_index_name
|
92
|
+
column_name = columns_or_expressions.select {|type, _, _| type == :column}.inject("") do |acc,(_,name,_)|
|
93
|
+
"#{acc}_#{name}"
|
94
|
+
end
|
95
|
+
adapter.index_name(table_name, :column => "#{column_name}_auto")
|
96
|
+
end
|
97
|
+
|
98
|
+
def check_index_name_length
|
99
|
+
if index_name.length > index_name_length
|
100
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
|
101
|
+
end
|
102
|
+
if adapter.index_name_exists?(table_name, index_name, false)
|
103
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def index_name_length
|
108
|
+
adapter.index_name_length
|
109
|
+
end
|
110
|
+
|
111
|
+
def adapter
|
112
|
+
ActiveRecord::Base.connection
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Peegee
|
2
|
+
module SchemaStatement
|
3
|
+
def add_index(table_name, *args)
|
4
|
+
options = args.last.respond_to?(:key?) ? args.pop : {}
|
5
|
+
column = args.first
|
6
|
+
|
7
|
+
index = Peegee::Index.new(:table_name => table_name,
|
8
|
+
:options => options)
|
9
|
+
if block_given?
|
10
|
+
yield index
|
11
|
+
else
|
12
|
+
index.column = column
|
13
|
+
end
|
14
|
+
|
15
|
+
if index.run_outside_transaction?
|
16
|
+
commit_db_transaction
|
17
|
+
execute(index.create_sql)
|
18
|
+
begin_db_transaction
|
19
|
+
else
|
20
|
+
execute(index.create_sql)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/peegee/version.rb
CHANGED
data/peegee.gemspec
CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "peegee"
|
7
7
|
s.version = Peegee::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Harold Giménez"]
|
9
|
+
s.authors = ["Harold Giménez", "Mike Burns"]
|
10
10
|
s.email = ["hgimenez@thoughtbot.com"]
|
11
11
|
s.homepage = "http://github.com/peegee"
|
12
12
|
s.summary = %q{PostgreSQL extensions for ActiveRecord}
|
13
|
-
s.description = %q{
|
13
|
+
s.description = %q{Introduces ActiveRecord to PostgreSQL, adding support for PostgreSQL specific features.}
|
14
14
|
|
15
15
|
s.add_dependency 'activerecord'
|
16
16
|
s.add_development_dependency 'pg'
|
@@ -18,8 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_development_dependency 'aruba'
|
19
19
|
s.add_development_dependency 'rspec-core'
|
20
20
|
s.add_development_dependency 'rspec-expectations'
|
21
|
-
s.add_development_dependency 'rails', '3.0.
|
21
|
+
s.add_development_dependency 'rails', '3.0.10'
|
22
22
|
s.add_development_dependency 'ruby-debug'
|
23
|
+
s.add_development_dependency 'herodotus'
|
23
24
|
|
24
25
|
s.files = `git ls-files`.split("\n")
|
25
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/index_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Peegee::Index, "creating SQL for a concurrent index" do
|
4
|
+
let(:table_name) { "users" }
|
5
|
+
let(:column) { "name" }
|
6
|
+
|
7
|
+
let(:indexerizer) do
|
8
|
+
Peegee::Index.new(
|
9
|
+
:table_name => table_name,
|
10
|
+
:column => column,
|
11
|
+
:options => {:concurrently => true})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "produces the proper SQL" do
|
15
|
+
indexerizer.create_sql.should == %{CREATE INDEX CONCURRENTLY "index_#{table_name}_on__#{column}_auto" ON "#{table_name}" ("#{column}" ) }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is to be run outside of a transaction" do
|
19
|
+
indexerizer.should be_run_outside_transaction
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Peegee::Index, "creating SQL for an index specifying a tablespace" do
|
24
|
+
let(:table_name) { "users" }
|
25
|
+
let(:column) { "name" }
|
26
|
+
let(:tablespace) { "indexspace" }
|
27
|
+
|
28
|
+
let(:indexerizer) do
|
29
|
+
Peegee::Index.new(
|
30
|
+
:table_name => table_name,
|
31
|
+
:column => column,
|
32
|
+
:options => {:tablespace => tablespace})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "produces the proper SQL" do
|
36
|
+
indexerizer.create_sql.should == %{CREATE INDEX "index_#{table_name}_on__#{column}_auto" ON "#{table_name}" ("#{column}" ) TABLESPACE #{tablespace}}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "is to be run inside of a transaction" do
|
40
|
+
indexerizer.should_not be_run_outside_transaction
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module SqlHelpers
|
4
|
+
def connection
|
5
|
+
@connection ||= begin
|
6
|
+
ActiveRecord::Base.establish_connection(
|
7
|
+
:adapter => 'postgresql',
|
8
|
+
:encoding => 'unicode',
|
9
|
+
:database => 'peegee_development'
|
10
|
+
)
|
11
|
+
ActiveRecord::Base.connection
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def select_all(sql)
|
16
|
+
connection.select_all sql
|
17
|
+
end
|
18
|
+
|
19
|
+
def oid(table_name)
|
20
|
+
select_all(<<-SQL).first['oid']
|
21
|
+
SELECT c.oid
|
22
|
+
FROM pg_catalog.pg_class c
|
23
|
+
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
24
|
+
WHERE c.relname = '#{table_name}'
|
25
|
+
AND pg_catalog.pg_table_is_visible(c.oid);
|
26
|
+
SQL
|
27
|
+
end
|
28
|
+
|
29
|
+
def disconnect_test_db
|
30
|
+
@connection and @connection.disconnect!
|
31
|
+
@connection = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_db
|
35
|
+
ActiveRecord::Base.establish_connection(
|
36
|
+
:adapter => 'postgresql',
|
37
|
+
:encoding => 'unicode',
|
38
|
+
:database => 'template1'
|
39
|
+
)
|
40
|
+
result = ActiveRecord::Base.connection.select_all %{SELECT * FROM pg_catalog.pg_database WHERE datname = 'peegee_development'}
|
41
|
+
unless result.size > 0
|
42
|
+
ActiveRecord::Base.connection.execute 'CREATE DATABASE peegee_development;'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peegee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
12
|
- "Harold Gim\xC3\xA9nez"
|
13
|
+
- Mike Burns
|
12
14
|
autorequire:
|
13
15
|
bindir: bin
|
14
16
|
cert_chain: []
|
15
17
|
|
16
|
-
date: 2011-
|
18
|
+
date: 2011-09-24 00:00:00 Z
|
17
19
|
dependencies:
|
18
20
|
- !ruby/object:Gem::Dependency
|
19
21
|
name: activerecord
|
@@ -107,12 +109,12 @@ dependencies:
|
|
107
109
|
requirements:
|
108
110
|
- - "="
|
109
111
|
- !ruby/object:Gem::Version
|
110
|
-
hash:
|
112
|
+
hash: 19
|
111
113
|
segments:
|
112
114
|
- 3
|
113
115
|
- 0
|
114
|
-
-
|
115
|
-
version: 3.0.
|
116
|
+
- 10
|
117
|
+
version: 3.0.10
|
116
118
|
type: :development
|
117
119
|
version_requirements: *id007
|
118
120
|
- !ruby/object:Gem::Dependency
|
@@ -129,7 +131,21 @@ dependencies:
|
|
129
131
|
version: "0"
|
130
132
|
type: :development
|
131
133
|
version_requirements: *id008
|
132
|
-
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: herodotus
|
136
|
+
prerelease: false
|
137
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
type: :development
|
147
|
+
version_requirements: *id009
|
148
|
+
description: Introduces ActiveRecord to PostgreSQL, adding support for PostgreSQL specific features.
|
133
149
|
email:
|
134
150
|
- hgimenez@thoughtbot.com
|
135
151
|
executables: []
|
@@ -140,9 +156,11 @@ extra_rdoc_files: []
|
|
140
156
|
|
141
157
|
files:
|
142
158
|
- .gitignore
|
159
|
+
- CHANGES
|
143
160
|
- Gemfile
|
144
|
-
-
|
161
|
+
- README.md
|
145
162
|
- Rakefile
|
163
|
+
- TODO
|
146
164
|
- features/create_indexes_in_migrations.feature
|
147
165
|
- features/step_definitions/migration_steps.rb
|
148
166
|
- features/step_definitions/postgres_steps.rb
|
@@ -150,8 +168,14 @@ files:
|
|
150
168
|
- features/support/env.rb
|
151
169
|
- features/support/sql_helpers.rb
|
152
170
|
- lib/peegee.rb
|
171
|
+
- lib/peegee/index.rb
|
172
|
+
- lib/peegee/quoting.rb
|
173
|
+
- lib/peegee/schema_statement.rb
|
153
174
|
- lib/peegee/version.rb
|
154
175
|
- peegee.gemspec
|
176
|
+
- spec/index_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/support/sql_helpers.rb
|
155
179
|
homepage: http://github.com/peegee
|
156
180
|
licenses: []
|
157
181
|
|
@@ -181,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
205
|
requirements: []
|
182
206
|
|
183
207
|
rubyforge_project:
|
184
|
-
rubygems_version: 1.
|
208
|
+
rubygems_version: 1.8.6
|
185
209
|
signing_key:
|
186
210
|
specification_version: 3
|
187
211
|
summary: PostgreSQL extensions for ActiveRecord
|
@@ -192,3 +216,6 @@ test_files:
|
|
192
216
|
- features/step_definitions/rails_steps.rb
|
193
217
|
- features/support/env.rb
|
194
218
|
- features/support/sql_helpers.rb
|
219
|
+
- spec/index_spec.rb
|
220
|
+
- spec/spec_helper.rb
|
221
|
+
- spec/support/sql_helpers.rb
|
data/Gemfile.lock
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
peegee (0.0.1)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
abstract (1.0.0)
|
11
|
-
actionmailer (3.0.7)
|
12
|
-
actionpack (= 3.0.7)
|
13
|
-
mail (~> 2.2.15)
|
14
|
-
actionpack (3.0.7)
|
15
|
-
activemodel (= 3.0.7)
|
16
|
-
activesupport (= 3.0.7)
|
17
|
-
builder (~> 2.1.2)
|
18
|
-
erubis (~> 2.6.6)
|
19
|
-
i18n (~> 0.5.0)
|
20
|
-
rack (~> 1.2.1)
|
21
|
-
rack-mount (~> 0.6.14)
|
22
|
-
rack-test (~> 0.5.7)
|
23
|
-
tzinfo (~> 0.3.23)
|
24
|
-
activemodel (3.0.7)
|
25
|
-
activesupport (= 3.0.7)
|
26
|
-
builder (~> 2.1.2)
|
27
|
-
i18n (~> 0.5.0)
|
28
|
-
activerecord (3.0.7)
|
29
|
-
activemodel (= 3.0.7)
|
30
|
-
activesupport (= 3.0.7)
|
31
|
-
arel (~> 2.0.2)
|
32
|
-
tzinfo (~> 0.3.23)
|
33
|
-
activeresource (3.0.7)
|
34
|
-
activemodel (= 3.0.7)
|
35
|
-
activesupport (= 3.0.7)
|
36
|
-
activesupport (3.0.7)
|
37
|
-
arel (2.0.10)
|
38
|
-
aruba (0.3.6)
|
39
|
-
childprocess (>= 0.1.7)
|
40
|
-
cucumber (>= 0.10.0)
|
41
|
-
rspec (>= 2.5.0)
|
42
|
-
builder (2.1.2)
|
43
|
-
childprocess (0.1.9)
|
44
|
-
ffi (~> 1.0.6)
|
45
|
-
columnize (0.3.2)
|
46
|
-
cucumber (0.10.3)
|
47
|
-
builder (>= 2.1.2)
|
48
|
-
diff-lcs (>= 1.1.2)
|
49
|
-
gherkin (>= 2.3.8)
|
50
|
-
json (>= 1.4.6)
|
51
|
-
term-ansicolor (>= 1.0.5)
|
52
|
-
diff-lcs (1.1.2)
|
53
|
-
erubis (2.6.6)
|
54
|
-
abstract (>= 1.0.0)
|
55
|
-
ffi (1.0.9)
|
56
|
-
gherkin (2.3.10)
|
57
|
-
json (>= 1.4.6)
|
58
|
-
i18n (0.5.0)
|
59
|
-
json (1.5.1)
|
60
|
-
linecache (0.43)
|
61
|
-
mail (2.2.19)
|
62
|
-
activesupport (>= 2.3.6)
|
63
|
-
i18n (>= 0.4.0)
|
64
|
-
mime-types (~> 1.16)
|
65
|
-
treetop (~> 1.4.8)
|
66
|
-
mime-types (1.16)
|
67
|
-
pg (0.11.0)
|
68
|
-
polyglot (0.3.1)
|
69
|
-
rack (1.2.3)
|
70
|
-
rack-mount (0.6.14)
|
71
|
-
rack (>= 1.0.0)
|
72
|
-
rack-test (0.5.7)
|
73
|
-
rack (>= 1.0)
|
74
|
-
rails (3.0.7)
|
75
|
-
actionmailer (= 3.0.7)
|
76
|
-
actionpack (= 3.0.7)
|
77
|
-
activerecord (= 3.0.7)
|
78
|
-
activeresource (= 3.0.7)
|
79
|
-
activesupport (= 3.0.7)
|
80
|
-
bundler (~> 1.0)
|
81
|
-
railties (= 3.0.7)
|
82
|
-
railties (3.0.7)
|
83
|
-
actionpack (= 3.0.7)
|
84
|
-
activesupport (= 3.0.7)
|
85
|
-
rake (>= 0.8.7)
|
86
|
-
thor (~> 0.14.4)
|
87
|
-
rake (0.8.7)
|
88
|
-
rspec (2.6.0)
|
89
|
-
rspec-core (~> 2.6.0)
|
90
|
-
rspec-expectations (~> 2.6.0)
|
91
|
-
rspec-mocks (~> 2.6.0)
|
92
|
-
rspec-core (2.6.3)
|
93
|
-
rspec-expectations (2.6.0)
|
94
|
-
diff-lcs (~> 1.1.2)
|
95
|
-
rspec-mocks (2.6.0)
|
96
|
-
ruby-debug (0.10.4)
|
97
|
-
columnize (>= 0.1)
|
98
|
-
ruby-debug-base (~> 0.10.4.0)
|
99
|
-
ruby-debug-base (0.10.4)
|
100
|
-
linecache (>= 0.3)
|
101
|
-
term-ansicolor (1.0.5)
|
102
|
-
thor (0.14.6)
|
103
|
-
treetop (1.4.9)
|
104
|
-
polyglot (>= 0.3.1)
|
105
|
-
tzinfo (0.3.27)
|
106
|
-
|
107
|
-
PLATFORMS
|
108
|
-
ruby
|
109
|
-
|
110
|
-
DEPENDENCIES
|
111
|
-
aruba
|
112
|
-
cucumber
|
113
|
-
peegee!
|
114
|
-
pg
|
115
|
-
rails (= 3.0.7)
|
116
|
-
rspec-core
|
117
|
-
rspec-expectations
|
118
|
-
ruby-debug
|