database_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/database_manager.gemspec +23 -0
- data/lib/database_manager/tasks.rake +115 -0
- data/lib/database_manager/tasks.rb +17 -0
- data/lib/database_manager.rb +8 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f58db5ce9412274e3909bc4ec4bb487a2f75d51
|
4
|
+
data.tar.gz: 3ec237da38d7e4b87f94e4478f90dd65fe7503d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c68cddd296da7731cf912952b27b78e27b2b4226b8aab4820931aef3565f41facf98960585b172151ccb596ccbf20a9a698920d26a5b7852888504fe08729d0a
|
7
|
+
data.tar.gz: aa57a4bdce6d16cfcdec60380def23a833a460bcd80c5a734abb6f752232338563df417c13a8bf582c0ba298f29e22bb4109edfa0bc6394688fa9f63f9deb028
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Indrek Juhkam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# DatabaseManager
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pg_manager`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'pg_manager'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install pg_manager
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pg_manager.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'database_manager'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ['SaleMove TechMovers']
|
9
|
+
spec.email = ['techmovers@salemove.com']
|
10
|
+
|
11
|
+
spec.summary = %q{}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = 'https://github.com/salemove/database_manager'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'inflecto'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
migrations_dir = 'db/migrate'
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
desc 'Create a new migration'
|
5
|
+
task :new_migration, [:migration_name] do |task, migration_name:|
|
6
|
+
require 'inflecto'
|
7
|
+
class_name = Inflecto.camelize(migration_name)
|
8
|
+
file_name = [Time.now.strftime('%Y%m%d%H%M%S'), migration_name].join('_') + '.rb'
|
9
|
+
|
10
|
+
body = <<-MIGRATION
|
11
|
+
class #{class_name} < ActiveRecord::Migration[5.1]
|
12
|
+
def up
|
13
|
+
end
|
14
|
+
|
15
|
+
def down
|
16
|
+
raise ActiveRecord::IrreversibleMigration
|
17
|
+
end
|
18
|
+
end
|
19
|
+
MIGRATION
|
20
|
+
|
21
|
+
FileUtils.mkdir_p('db/migrate')
|
22
|
+
File.open("db/migrate/#{file_name}", 'w+') do |file|
|
23
|
+
file.write(body)
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "Created a new migration"
|
27
|
+
puts " db/migrate/#{file_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
task :environment do
|
31
|
+
ActiveRecord::Base.establish_connection(DatabaseManager::Tasks.config)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Migrate the database'
|
35
|
+
task migrate: :environment do
|
36
|
+
ActiveRecord::Migration.verbose = true
|
37
|
+
ActiveRecord::Migrator.migrate migrations_dir, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
38
|
+
Rake::Task['db:structure:dump'].invoke
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :migrate do
|
42
|
+
desc 'Rollbacks one migration and then migrates again'
|
43
|
+
task redo: :environment do
|
44
|
+
Rake::Task['db:rollback'].invoke
|
45
|
+
Rake::Task['db:migrate'].invoke
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
task :rollback, [:steps] => :environment do |task, args|
|
50
|
+
steps = if args[:steps] then args[:steps].to_i else 1 end
|
51
|
+
ActiveRecord::Migration.verbose = true
|
52
|
+
ActiveRecord::Migrator.rollback migrations_dir, steps
|
53
|
+
Rake::Task['db:structure:dump'].invoke
|
54
|
+
end
|
55
|
+
|
56
|
+
namespace :structure do
|
57
|
+
desc 'Dump the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql'
|
58
|
+
task dump: :environment do
|
59
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump(
|
60
|
+
DatabaseManager::Tasks.config.stringify_keys, 'db/structure.sql'
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Recreate the databases from the structure.sql file"
|
65
|
+
task load: :environment do
|
66
|
+
if File.exists?('db/structure.sql')
|
67
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_load(
|
68
|
+
DatabaseManager::Tasks.config.stringify_keys, 'db/structure.sql'
|
69
|
+
)
|
70
|
+
else
|
71
|
+
puts 'File db/structure.sql does not exist. Skipping structure:load.'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
desc 'Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)'
|
77
|
+
task :setup do
|
78
|
+
ActiveRecord::Tasks::DatabaseTasks.purge DatabaseManager::Tasks.config.stringify_keys
|
79
|
+
Rake::Task['db:structure:load'].invoke
|
80
|
+
# Structure load doesnt load migrations, but since it holds everything needed for DB, we can mark the migrations as done
|
81
|
+
Rake::Task['db:mark_migrations_done'].invoke
|
82
|
+
Rake::Task['db:seed'].invoke
|
83
|
+
end
|
84
|
+
|
85
|
+
task :mark_migrations_done do
|
86
|
+
pending_migrations = ActiveRecord::Migrator.open('db/migrate').pending_migrations
|
87
|
+
if pending_migrations.any?
|
88
|
+
pending_migrations.each do |m|
|
89
|
+
ActiveRecord::Base.connection.execute("INSERT INTO schema_migrations (version) VALUES (#{m.version});")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'Load the seed data from db/seeds.rb'
|
95
|
+
task :seed do
|
96
|
+
Rake::Task['db:abort_if_pending_migrations'].invoke
|
97
|
+
if File.exists?('db/seeds.rb')
|
98
|
+
load('db/seeds.rb')
|
99
|
+
else
|
100
|
+
puts 'File db/seeds.rb does not exist. Skipping loading seeds.'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
task abort_if_pending_migrations: :environment do
|
105
|
+
pending_migrations = ActiveRecord::Migrator.open('db/migrate').pending_migrations
|
106
|
+
|
107
|
+
if pending_migrations.any?
|
108
|
+
puts "You have #{pending_migrations.size} pending #{pending_migrations.size > 1 ? 'migrations:' : 'migration:'}"
|
109
|
+
pending_migrations.each do |pending_migration|
|
110
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
111
|
+
end
|
112
|
+
abort %{Run `rake db:migrate` to update your database then try again.}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DatabaseManager
|
2
|
+
module Tasks
|
3
|
+
def self.config
|
4
|
+
@config
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.config=(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load_rake_tasks(db_config)
|
12
|
+
require 'active_record'
|
13
|
+
self.config = db_config
|
14
|
+
load(File.dirname(__FILE__) + '/tasks.rake')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: database_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SaleMove TechMovers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: inflecto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- techmovers@salemove.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- database_manager.gemspec
|
70
|
+
- lib/database_manager.rb
|
71
|
+
- lib/database_manager/tasks.rake
|
72
|
+
- lib/database_manager/tasks.rb
|
73
|
+
homepage: https://github.com/salemove/database_manager
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: ''
|
97
|
+
test_files: []
|