Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Commit 89df543

Browse files
committed
init
1 parent 81a5785 commit 89df543

26 files changed

+405
-0
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo: false
2+
language: ruby
3+
rvm:
4+
- 2.3.0
5+
before_install: gem install bundler -v 1.14.3

CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at adamluzsi@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in rack-app-db.gemspec
4+
gemspec

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Rack::App::SeQueL
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/rack/app/db`. 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 'rack-app-db'
13+
```
14+
15+
And then execute:
16+
17+
$ bundle
18+
19+
Or install it yourself as:
20+
21+
$ gem install rack-app-db
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/Adam Luzsi/rack-app-db. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36+

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task :default => :spec

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

Vagrantfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
5+
# configures the configuration version (we support older styles for
6+
# backwards compatibility). Please don't change it unless you know what
7+
# you're doing.
8+
Vagrant.configure('2') do |config|
9+
10+
config.vm.provider "virtualbox" do |v|
11+
v.name = File.basename(__dir__)
12+
end
13+
14+
config.vm.box = 'jnetocurti/postgresql-9.6_wildfly-10'
15+
config.vm.network :forwarded_port, guest: 5432, host: 5432
16+
config.vm.network :private_network, ip: '192.168.1.78'
17+
18+
config.vm.provision 'shell', privileged: true, inline: <<-SHELL
19+
set -euo pipefail
20+
IFS=$'\n\t'
21+
22+
sh /vagrant/script/vagrant/init.sh
23+
sh /vagrant/script/vagrant/make.sh
24+
sh /vagrant/script/vagrant/git.sh
25+
sh /vagrant/script/vagrant/pg.sh
26+
SHELL
27+
28+
end

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "rack/app/db"
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__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -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

config.ru

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
2+
require 'rack/app'
3+
require 'rack/app/db'
4+
5+
class App < Rack::App
6+
apply_extensions :sequel
7+
end
8+
9+
run App

env.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export DATABASE_URL="postgres://vagrant:vagrant@192.168.1.78/vagrant"

lib/rack/app/sequel.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'sequel'
2+
require 'rack/app'
3+
module Rack::App::SeQueL
4+
require 'rack/app/db/ext'
5+
require 'rack/app/db/version'
6+
require 'rack/app/db/migration'
7+
8+
def open_connection
9+
Sequel.connect(ENV.fetch('DATABASE_URL'))
10+
end
11+
12+
module_function :connection
13+
end

lib/rack/app/sequel/ext.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rack::App::Extension.register :sequel do
2+
cli(&Rack::App::SeQueL::Migration::CLI)
3+
end

lib/rack/app/sequel/migration.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Rack::App::SeQueL::Migration
2+
require 'rack/app/db/migration/template'
3+
require 'rack/app/db/migration/cli'
4+
DEFAULT_DIRECTORY = 'db/migrations'.freeze
5+
end

lib/rack/app/sequel/migration/cli.rb

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Rack::App::SeQueL::Migration::CLI = lambda do
2+
3+
command "db:migrate" do
4+
description 'Run migrations'
5+
6+
option '-v', '--version [TIMESTAMP]', 'set to what db migration version number should db to be set' do |string|
7+
options[:version] = string
8+
end
9+
10+
option '--allow-missing-migration-files', 'In some cases, you may want to allow a migration in the database that does not exist in the filesystem' do
11+
options[:allow_missing_migration_files] = true
12+
end
13+
14+
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |string|
15+
options[:migration_directory] = string
16+
end
17+
18+
action do
19+
20+
options[:migration_directory] ||= Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
21+
22+
Sequel.extension(:migration)
23+
db = Rack::App::SeQueL.open_connection
24+
db = Sequel.connect(ENV.fetch('DATABASE_URL'))
25+
26+
migration_config = {}
27+
if options[:allow_missing_migration_files]
28+
migration_config[:allow_missing_migration_files]= true
29+
end
30+
31+
if options[:version]
32+
STDOUT.puts "Migrating to version #{options[:version]}"
33+
migration_config[:target]= options[:version].to_i
34+
end
35+
36+
Sequel::Migrator.run(db, options[:migration_directory], migration_config)
37+
38+
STDOUT.puts('Migration completed')
39+
end
40+
41+
end
42+
43+
command "db:migration:create" do
44+
description 'create migration patch'
45+
46+
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |string|
47+
options[:migration_directory] = string
48+
end
49+
50+
action do |*name_parts|
51+
options[:migration_directory] ||= Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
52+
name = name_parts.join('_')
53+
54+
require 'fileutils'
55+
FileUtils.mkdir_p(options[:migration_directory])
56+
timestamp = Time.now.to_i
57+
filebasename = [timestamp.to_s, name].join('_') + '.rb'
58+
file_path = File.join(options[:migration_directory], filebasename)
59+
File.write(file_path, Rack::App::SeQueL::Migration::TEMPLATE)
60+
61+
STDOUT.puts(file_path)
62+
end
63+
64+
end
65+
66+
end
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Rack::App::SeQueL::Migration::TEMPLATE = <<-RUBY
2+
3+
Sequel.migration do
4+
up do
5+
end
6+
7+
down do
8+
end
9+
end
10+
11+
RUBY
12+
13+
Rack::App::SeQueL::Migration::TEMPLATE.freeze

lib/rack/app/sequel/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'rack/app/db'
2+
file_path = File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'VERSION')
3+
Rack::App::SeQueL::VERSION = File.read(file_path).strip

rack-app-sequel.gemspec

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'rack/app/sequel/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "rack-app-sequel"
8+
spec.version = Rack::App::SeQueL::VERSION
9+
spec.authors = ["Adam Luzsi"]
10+
spec.email = ["adamluzsi@gmail.com"]
11+
12+
spec.summary = %q{rack-app db usecase integration for migration and modelling}
13+
spec.description = %q{rack-app db usecase integration for migration and modelling}
14+
spec.homepage = "https://github.com/rack-app/rack-app-sequel"
15+
16+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
17+
f.match(%r{^(test|spec|features)/})
18+
end
19+
spec.bindir = "exe"
20+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21+
spec.require_paths = ["lib"]
22+
23+
spec.add_development_dependency "bundler", "~> 1.14"
24+
spec.add_development_dependency "rake", "~> 10.0"
25+
spec.add_development_dependency "rspec", "~> 3.0"
26+
27+
spec.add_dependency "sequel", ">= 4.0.0"
28+
end

script/database

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
COMMAND=$1
6+
7+
function main() {
8+
case "$COMMAND" in
9+
up) up
10+
;;
11+
down) down
12+
;;
13+
destroy) destroy
14+
;;
15+
*) echo "invalid command: script/database up|down|destroy"
16+
;;
17+
esac
18+
}
19+
20+
function up() {
21+
vagrant up
22+
}
23+
24+
function down() {
25+
vagrant suspend
26+
}
27+
28+
function destroy() {
29+
vagrant destroy -f
30+
}
31+
32+
main

script/vagrant/git.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
GIT_FLAG=$FLAG_FOLDER/git
4+
5+
if [ ! -f $GIT_FLAG ];then
6+
sudo apt-get install -y git
7+
8+
touch $GIT_FLAG
9+
fi

script/vagrant/init.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
apt-get update > /dev/null
4+
export FLAG_FOLDER="/home/vagrant/.installs"
5+
6+
if [ ! -d $FLAG_FOLDER ];then
7+
mkdir -p $FLAG_FOLDER
8+
fi

0 commit comments

Comments
 (0)