sequel-db_tasks 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9b88935e4a3b26336e0486debb41ddf602eabc687913453aeb7aca56553c1d33
4
+ data.tar.gz: 0f925a0948ed134954523c7b845434fe3e7dcd971d0d5af7c79e96f8a1ad1a2e
5
+ SHA512:
6
+ metadata.gz: c80b76b56cb336a42d246b653179d8fda48631cd595b73d4fce7680da61ad820137b8da51ccf9ae7f992255aa4af34631d2bdd277af1bda2df7c4e77303aedd7
7
+ data.tar.gz: 1f15c1a78ac1eaf4986cde3434d0a8d51957059b1541aa3bd406202d0b82990d78a93d29b7bb0f91e3a8d3779bc5571aff681dcf78e650412ba358e883f199dc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sequel-db_tasks.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Victor Afanasev
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,58 @@
1
+ # Sequel::DbTasks
2
+ Rake CLI tasks for Sequel ORM and Postgres. All available tasks:
3
+
4
+ ```
5
+ rake db:create # Create database
6
+ rake db:drop # Drop database
7
+ rake db:gm[name] # Generate migration file
8
+ rake db:migrate[version] # Run migrations
9
+ rake db:schema:print # Print current database schema
10
+ ```
11
+
12
+ There is no `config/database.yml` file. Gem works with `DATABASE_URL` (https://github.com/jeremyevans/sequel/blob/master/doc/opening_databases.rdoc#using-the-sequelconnect-method), which is should match exactly this format:
13
+
14
+ ```
15
+ postgres://user:password@localhost/database_name
16
+ ```
17
+
18
+ By default gem takes db_url from DATABASE_URL env variable. You can set other value (see _Installation_ below).
19
+
20
+ ## Installation
21
+ Gemfile:
22
+
23
+ ```ruby
24
+ gem 'dotenv'
25
+ gem 'sequel-db_tasks', require: false
26
+ ```
27
+
28
+ Run `bundle install`.
29
+
30
+ Rakefile:
31
+
32
+ ```ruby
33
+ require 'sequel/db_tasks'
34
+ require 'dotenv/load' # require dotenv/load (dotenv gem) to get value of DATABASE_URL env variable inside .env file
35
+
36
+ Sequel::DbTasks.load!
37
+ ```
38
+
39
+ You can tweak settings using configure block:
40
+
41
+ ```ruby
42
+ # Rakefile
43
+
44
+ Sequel::DbTasks.configure do |config|
45
+ database_url: ENV["DATABASE_URL"], # default value
46
+ migrations_path: "db/migrate" # default value
47
+ end
48
+
49
+ Sequel::DbTasks.load!
50
+ ```
51
+
52
+ ## Notes
53
+
54
+ Inspired by https://github.com/sandelius/sequel-rake
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sequel/db_tasks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ require 'ostruct'
2
+ require "sequel/db_tasks/version"
3
+
4
+ module Sequel
5
+ module DbTasks
6
+ def self.configuration
7
+ @configuration ||= OpenStruct.new(
8
+ database_url: ENV["DATABASE_URL"],
9
+ migrations_path: "db/migrate"
10
+ )
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ end
16
+
17
+ def self.load!
18
+ Rake.application.add_import "#{__dir__}/db_tasks/tasks.rake"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,82 @@
1
+ # All possible rails db tasks https://jacopretorius.net/2014/02/all-rails-db-rake-tasks-and-what-they-do.html
2
+
3
+ namespace :db do
4
+ task :preload do
5
+ require 'uri'
6
+
7
+ url = Sequel::DbTasks.configuration.database_url
8
+ uri = URI.parse(url)
9
+ raise "DB adapter is not postgres" if uri.scheme != "postgres"
10
+
11
+ @conf = {
12
+ url: url,
13
+ db: uri.path.sub("/", ""),
14
+ host: uri.host,
15
+ port: uri.port,
16
+ user: uri.user,
17
+ password: uri.password
18
+ }
19
+ end
20
+
21
+ # https://www.postgresql.org/docs/current/app-createdb.html
22
+ desc "Create database"
23
+ task create: :preload do
24
+ env = { "PGPASSWORD" => @conf[:password] }
25
+ if system env, "createdb", @conf[:db], "-h", @conf[:host], "-p", @conf[:port].to_s, "-U", @conf[:user]
26
+ puts "Created database '#{@conf[:db]}'"
27
+ end
28
+ end
29
+
30
+ # https://www.postgresql.org/docs/9.3/app-dropdb.html
31
+ desc "Drop database"
32
+ task drop: :preload do
33
+ env = { "PGPASSWORD" => @conf[:password] }
34
+ if system env, "dropdb", @conf[:db], "-h", @conf[:host], "-p", @conf[:port].to_s, "-U", @conf[:user]
35
+ puts "Dropped database '#{@conf[:db]}'"
36
+ end
37
+ end
38
+
39
+ # https://github.com/jeremyevans/sequel/blob/master/doc/migration.rdoc#a-basic-migration
40
+ desc "Generate migration file"
41
+ task :gm, [:name] do |t, args|
42
+ migrations_path = Sequel::DbTasks.configuration.migrations_path
43
+ mkdir_p migrations_path
44
+
45
+ time = Time.now.utc.strftime("%Y%m%d%H%M%S")
46
+ filename = File.join(migrations_path, "#{time}_#{args.name}.rb")
47
+ File.write(filename,
48
+ <<~RUBY
49
+ # #{filename}
50
+
51
+ Sequel.migration do
52
+ change do
53
+
54
+ end
55
+ end
56
+ RUBY
57
+ )
58
+
59
+ puts "Created migration '#{filename}'"
60
+ end
61
+
62
+ # https://github.com/jeremyevans/sequel/blob/master/doc/migration.rdoc#running-migrations-from-a-rake-task
63
+ desc "Run migrations"
64
+ task :migrate, [:version] do |t, args|
65
+ Rake::Task["db:preload"].execute
66
+ require 'sequel/core'
67
+ require 'logger'
68
+
69
+ Sequel.extension :migration
70
+ version = args[:version].to_i if args[:version]
71
+
72
+ Sequel.connect(@conf[:url], logger: Logger.new(STDOUT)) do |db|
73
+ Sequel::Migrator.run(db, Sequel::DbTasks.configuration.migrations_path, target: version)
74
+ end
75
+ end
76
+
77
+ # https://github.com/jeremyevans/sequel/blob/master/doc/migration.rdoc#dumping-the-current-schema-as-a-migration
78
+ desc "Print current database schema"
79
+ task :'schema:print' => :preload do
80
+ exec "bundle", "exec", "sequel", "-d", @conf[:url]
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ module Sequel
2
+ module DbTasks
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sequel/db_tasks/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sequel-db_tasks"
8
+ spec.version = Sequel::DbTasks::VERSION
9
+ spec.authors = ["Victor Afanasev"]
10
+ spec.email = ["vicfreefly@gmail.com"]
11
+
12
+ spec.summary = "Rake database tasks for Sequel and Postgres"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/vifreefly/sequel-db_tasks"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "sequel"
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-db_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Afanasev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: Rake database tasks for Sequel and Postgres
70
+ email:
71
+ - vicfreefly@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/sequel/db_tasks.rb
84
+ - lib/sequel/db_tasks/tasks.rake
85
+ - lib/sequel/db_tasks/version.rb
86
+ - sequel-db_tasks.gemspec
87
+ homepage: https://github.com/vifreefly/sequel-db_tasks
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.7.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Rake database tasks for Sequel and Postgres
111
+ test_files: []