provideal-migration-helpers 1.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/Rakefile +16 -0
- data/VERSION +1 -0
- data/init.rb +11 -0
- data/lib/migration_helpers.rb +26 -0
- data/migration-helpers.gemspec +36 -0
- metadata +58 -0
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "migration-helpers"
|
9
|
+
gemspec.summary = "A collection of Rails migration helpers"
|
10
|
+
gemspec.email = "info@provideal.net"
|
11
|
+
gemspec.homepage = "http://github.com/provideal/migration-helpers/"
|
12
|
+
gemspec.authors = ["René Sprotte"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/init.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'migration_helpers'
|
2
|
+
|
3
|
+
# Support for MySQL
|
4
|
+
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
|
5
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.send :include, Provideal::MigrationHelpers
|
6
|
+
end
|
7
|
+
|
8
|
+
# Support for PostgreSQL
|
9
|
+
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
10
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, Provideal::MigrationHelpers
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Provideal
|
2
|
+
module MigrationHelpers
|
3
|
+
def add_foreign_key(from_table, from_columns, to_table, to_columns, options = {})
|
4
|
+
from_columns = [from_columns] unless from_columns.is_a? Array
|
5
|
+
to_columns = [to_columns] unless to_columns.is_a? Array
|
6
|
+
|
7
|
+
constraint_name = "fk_#{from_table}_#{from_columns.join('_')}"
|
8
|
+
|
9
|
+
sql = "ALTER TABLE #{from_table} ADD CONSTRAINT #{constraint_name} FOREIGN KEY (#{from_columns.join(',')}) REFERENCES #{to_table}(#{to_columns.join(',')})"
|
10
|
+
|
11
|
+
# Actions
|
12
|
+
sql << " ON DELETE #{options[:on_delete]}" unless options[:on_delete].nil?
|
13
|
+
sql << " ON UPDATE #{options[:on_update]}" unless options[:on_update].nil?
|
14
|
+
|
15
|
+
execute sql
|
16
|
+
end
|
17
|
+
|
18
|
+
def remove_foreign_key(from_table, from_columns)
|
19
|
+
from_columns = [from_columns] unless from_columns.is_a? Array
|
20
|
+
constraint_name = "fk_#{from_table}_#{from_columns.join('_')}"
|
21
|
+
|
22
|
+
sql = "ALTER TABLE #{from_table} DROP CONSTRAINT #{constraint_name}"
|
23
|
+
execute sql
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{migration-helpers}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["René Sprotte"]
|
12
|
+
s.date = %q{2009-09-03}
|
13
|
+
s.email = %q{info@provideal.net}
|
14
|
+
s.files = [
|
15
|
+
"Rakefile",
|
16
|
+
"VERSION",
|
17
|
+
"init.rb",
|
18
|
+
"lib/migration_helpers.rb",
|
19
|
+
"migration-helpers.gemspec"
|
20
|
+
]
|
21
|
+
s.homepage = %q{http://github.com/provideal/migration-helpers/}
|
22
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
s.rubygems_version = %q{1.3.5}
|
25
|
+
s.summary = %q{A collection of Rails migration helpers}
|
26
|
+
|
27
|
+
if s.respond_to? :specification_version then
|
28
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
29
|
+
s.specification_version = 3
|
30
|
+
|
31
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
32
|
+
else
|
33
|
+
end
|
34
|
+
else
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: provideal-migration-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Ren\xC3\xA9 Sprotte"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: info@provideal.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- VERSION
|
27
|
+
- init.rb
|
28
|
+
- lib/migration_helpers.rb
|
29
|
+
- migration-helpers.gemspec
|
30
|
+
has_rdoc: false
|
31
|
+
homepage: http://github.com/provideal/migration-helpers/
|
32
|
+
licenses:
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.3.5
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: A collection of Rails migration helpers
|
57
|
+
test_files: []
|
58
|
+
|