ejhayes_standalone_migrations 2.2.0
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/.travis.yml +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +113 -0
- data/LICENSE +20 -0
- data/README.markdown +265 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/example/.gitignore +5 -0
- data/example/Rakefile +9 -0
- data/example/db/config.yml +15 -0
- data/example/db/migrate/20120930053225_create_table_awesome_migration.rb +7 -0
- data/lib/standalone_migrations.rb +20 -0
- data/lib/standalone_migrations/callbacks.rb +13 -0
- data/lib/standalone_migrations/configurator.rb +88 -0
- data/lib/standalone_migrations/generator.rb +11 -0
- data/lib/standalone_migrations/minimal_railtie_config.rb +10 -0
- data/lib/standalone_migrations/tasks.rb +36 -0
- data/lib/standalone_migrations/tasks/connection.rake +8 -0
- data/lib/standalone_migrations/tasks/db/new_migration.rake +19 -0
- data/lib/standalone_migrations/tasks/environment.rake +3 -0
- data/lib/tasks/standalone_migrations.rb +10 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/standalone_migrations/callbacks_spec.rb +48 -0
- data/spec/standalone_migrations/configurator_spec.rb +263 -0
- data/spec/standalone_migrations_spec.rb +331 -0
- data/standalone_migrations.gemspec +74 -0
- data/vendor/migration_helpers/MIT-LICENSE +20 -0
- data/vendor/migration_helpers/README.markdown +92 -0
- data/vendor/migration_helpers/init.rb +4 -0
- data/vendor/migration_helpers/lib/migration_helper.rb +51 -0
- metadata +129 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module MigrationConstraintHelpers
|
2
|
+
|
3
|
+
# Creates a foreign key from +table+.+field+ against referenced_table.referenced_field
|
4
|
+
#
|
5
|
+
# table: The tablename
|
6
|
+
# field: A field of the table
|
7
|
+
# referenced_table: The table which contains the field referenced
|
8
|
+
# referenced_field: The field (which should be part of the primary key) of the referenced table
|
9
|
+
# cascade: delete & update on cascade?
|
10
|
+
def foreign_key(table, field, referenced_table, referenced_field = :id, cascade = true)
|
11
|
+
execute "ALTER TABLE #{table} ADD CONSTRAINT #{constraint_name(table, field)}
|
12
|
+
FOREIGN KEY #{constraint_name(table, field)} (#{field_list(field)})
|
13
|
+
REFERENCES #{referenced_table}(#{field_list(referenced_field)})
|
14
|
+
#{(cascade ? 'ON DELETE CASCADE ON UPDATE CASCADE' : '')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Drops a foreign key from +table+.+field+ that has been created before with
|
18
|
+
# foreign_key method
|
19
|
+
#
|
20
|
+
# table: The table name
|
21
|
+
# field: A field (or array of fields) of the table
|
22
|
+
def drop_foreign_key(table, field)
|
23
|
+
execute "ALTER TABLE #{table} DROP FOREIGN KEY #{constraint_name(table, field)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a primary key for +table+, which right now HAS NOT primary key defined
|
27
|
+
#
|
28
|
+
# table: The table name
|
29
|
+
# field: A field (or array of fields) of the table that will be part of the primary key
|
30
|
+
def primary_key(table, field)
|
31
|
+
execute "ALTER TABLE #{table} ADD PRIMARY KEY(#{field_list(field)})"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Creates a constraint name for table and field given as parameters
|
37
|
+
#
|
38
|
+
# table: The table name
|
39
|
+
# field: A field of the table
|
40
|
+
def constraint_name(table, field)
|
41
|
+
"fk_#{table}_#{field_list_name(field)}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def field_list(fields)
|
45
|
+
fields.is_a?(Array) ? fields.join(',') : fields
|
46
|
+
end
|
47
|
+
|
48
|
+
def field_list_name(fields)
|
49
|
+
fields.is_a?(Array) ? fields.join('_') : fields
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ejhayes_standalone_migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Todd Huss
|
9
|
+
- Michael Grosser
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '10.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '10.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: activerecord
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.2'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: railties
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.2'
|
63
|
+
description:
|
64
|
+
email: thuss@gabrito.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files:
|
68
|
+
- LICENSE
|
69
|
+
- README.markdown
|
70
|
+
files:
|
71
|
+
- .travis.yml
|
72
|
+
- Gemfile
|
73
|
+
- Gemfile.lock
|
74
|
+
- LICENSE
|
75
|
+
- README.markdown
|
76
|
+
- Rakefile
|
77
|
+
- VERSION
|
78
|
+
- example/.gitignore
|
79
|
+
- example/Rakefile
|
80
|
+
- example/db/config.yml
|
81
|
+
- example/db/migrate/20120930053225_create_table_awesome_migration.rb
|
82
|
+
- lib/standalone_migrations.rb
|
83
|
+
- lib/standalone_migrations/callbacks.rb
|
84
|
+
- lib/standalone_migrations/configurator.rb
|
85
|
+
- lib/standalone_migrations/generator.rb
|
86
|
+
- lib/standalone_migrations/minimal_railtie_config.rb
|
87
|
+
- lib/standalone_migrations/tasks.rb
|
88
|
+
- lib/standalone_migrations/tasks/connection.rake
|
89
|
+
- lib/standalone_migrations/tasks/db/new_migration.rake
|
90
|
+
- lib/standalone_migrations/tasks/environment.rake
|
91
|
+
- lib/tasks/standalone_migrations.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/standalone_migrations/callbacks_spec.rb
|
94
|
+
- spec/standalone_migrations/configurator_spec.rb
|
95
|
+
- spec/standalone_migrations_spec.rb
|
96
|
+
- standalone_migrations.gemspec
|
97
|
+
- vendor/migration_helpers/MIT-LICENSE
|
98
|
+
- vendor/migration_helpers/README.markdown
|
99
|
+
- vendor/migration_helpers/init.rb
|
100
|
+
- vendor/migration_helpers/lib/migration_helper.rb
|
101
|
+
homepage: http://github.com/thuss/standalone-migrations
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -175923346996612782
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.23.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: A thin wrapper to use Rails Migrations in non Rails projects
|
129
|
+
test_files: []
|