activerecord-postgres-uuid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/active_record/connection_adapter_with_uuid.rb +38 -0
- data/lib/active_record/postgresql/uuid/version.rb +9 -0
- data/lib/active_record/postgresql/uuid_column.rb +52 -0
- data/lib/activerecord-postgres-uuid.rb +1 -0
- data/lib/templates/setup_uuid_91.rb +10 -0
- data/uuid_support.gemspec +20 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ivan Vanderbyl
|
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,29 @@
|
|
1
|
+
# UuidSupport
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'uuid_support'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install uuid_support
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
|
4
|
+
class TableDefinition
|
5
|
+
|
6
|
+
# Adds hstore type for migrations. So you can add columns to a table like:
|
7
|
+
# create_table :people, :id => false do |t|
|
8
|
+
# ...
|
9
|
+
# t.uuid :id, :null => false
|
10
|
+
# ...
|
11
|
+
# end
|
12
|
+
def uuid(*args)
|
13
|
+
options = args.extract_options!
|
14
|
+
column_names = args
|
15
|
+
column_names.each { |name| column(name, 'uuid', options) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class PostgreSQLColumn < Column
|
21
|
+
|
22
|
+
# Adds the uuid type for the column.
|
23
|
+
def simplified_type_with_uuid(field_type)
|
24
|
+
field_type == 'uuid' ? :uuid : simplified_type_without_uuid(field_type)
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method_chain :simplified_type, :uuid
|
28
|
+
end
|
29
|
+
|
30
|
+
class PostgreSQLAdapter < AbstractAdapter
|
31
|
+
def native_database_types_with_uuid
|
32
|
+
native_database_types_without_hstore.merge({:uuid => { :name => "uuid" }})
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method_chain :native_database_types, :uuid
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require 'rails'
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
require 'pg'
|
6
|
+
|
7
|
+
require "active_record/postgresql/uuid/version"
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
module PostgreSQL
|
11
|
+
class UUIDColumn < Rails::Railtie
|
12
|
+
|
13
|
+
initializer 'activerecord-postgres-uuid' do
|
14
|
+
ActiveSupport.on_load :active_record do
|
15
|
+
require "active_record/connection_adapter_with_uuid"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Creates the hstore:setup generator. This generator creates a migration that
|
20
|
+
# adds hstore support for your database. If fact, it's just the sql from the
|
21
|
+
# contrib inside a migration. But it' s handy, isn't it?
|
22
|
+
#
|
23
|
+
# To use your generator, simply run it in your project:
|
24
|
+
#
|
25
|
+
# rails g hstore:setup
|
26
|
+
class Setup < Rails::Generators::Base
|
27
|
+
include Rails::Generators::Migration
|
28
|
+
|
29
|
+
def self.source_root
|
30
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.next_migration_number(dirname)
|
34
|
+
if ActiveRecord::Base.timestamped_migrations
|
35
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
36
|
+
else
|
37
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_migration_file
|
42
|
+
pgversion = ActiveRecord::Base.connection.send(:postgresql_version)
|
43
|
+
if pgversion < 90100
|
44
|
+
raise RuntimeError, "UUID is not supported on Postgress < 9.1"
|
45
|
+
else
|
46
|
+
migration_template 'setup_uuid_91.rb', 'db/migrate/setup_uuid.rb'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "active_record/postgresql/uuid_column"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/active_record/postgresql/uuid/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ivan Vanderbyl"]
|
6
|
+
gem.email = ["ivanvanderbyl@me.com"]
|
7
|
+
gem.description = %q{Adds support for PostgreSQL 128 bit UUID column type to ActiveRecord}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "activerecord-postgres-uuid"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ActiveRecord::PostgreSQL::UUIDColumn::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "activerecord", ">= 3.1.0"
|
19
|
+
gem.add_dependency "pg", ">= 0.12.0"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-postgres-uuid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Vanderbyl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &70144170872540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70144170872540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pg
|
27
|
+
requirement: &70144170877740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.12.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70144170877740
|
36
|
+
description: Adds support for PostgreSQL 128 bit UUID column type to ActiveRecord
|
37
|
+
email:
|
38
|
+
- ivanvanderbyl@me.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/active_record/connection_adapter_with_uuid.rb
|
49
|
+
- lib/active_record/postgresql/uuid/version.rb
|
50
|
+
- lib/active_record/postgresql/uuid_column.rb
|
51
|
+
- lib/activerecord-postgres-uuid.rb
|
52
|
+
- lib/templates/setup_uuid_91.rb
|
53
|
+
- uuid_support.gemspec
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.15
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Adds support for PostgreSQL 128 bit UUID column type to ActiveRecord
|
78
|
+
test_files: []
|