refresher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0d02ca1b94a9af4aa2786669ed85345e5d6bdf0
4
+ data.tar.gz: 66199016383e6878e09621c8b3cf46d79aa12a50
5
+ SHA512:
6
+ metadata.gz: fa59a2eaa73d0dd0daddf6da814906f275fca293e0c9760ad443a7cf5797ae9f263e3ad7e1d082459d4feeb600c444c8437548169a237a377b87e23fb536164e
7
+ data.tar.gz: 007b3b89459a793eb7714ecd1ed6ce424556128c78b20e102d00076af2e77087f4cfa1292b7985b364c0d95922979df335252555564ceaa0a3c690dd8253f3f2
data/lib/refresher.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'refresher/railtie'
2
+
3
+ module Refresher
4
+
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module Refresher
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :refresher
6
+
7
+ rake_tasks do
8
+ load "tasks/db_refresher.rake"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ DROP DATABASE s{db_name};
2
+ CREATE DATABASE s{db_name};
3
+ CREATE USER s{user_name} WITH PASSWORD 'password';
4
+ ALTER USER s{user_name} with createdb;
5
+ GRANT ALL PRIVILEGES ON DATABASE s{db_name} TO s{user_name};
6
+ ALTER DATABASE "s{db_name}" OWNER TO "s{user_name}";
7
+
8
+ \c s{db_name};
9
+ ALTER SCHEMA public OWNER TO "s{user_name}";
10
+
@@ -0,0 +1,44 @@
1
+ namespace :db_refresher do
2
+ desc 'Refresh current db state to all migrations (from cache if available)'
3
+ task refresh: :environment do
4
+
5
+ conn = nil
6
+ safe_schema_head_sql = nil
7
+ use_safe = false
8
+
9
+ begin
10
+ conn = ActiveRecord::Base.connection
11
+ safe_schema_head_sql = "drop schema public cascade; create schema public;"
12
+ use_safe = true
13
+ sql = ActiveRecord::Base.send(:sanitize_sql_array, safe_schema_head_sql)
14
+ conn.execute(sql)
15
+ rescue ActiveRecord::NoDatabaseError
16
+ safe_schema_head_sql = File.read(File.join(File.dirname(__FILE__), '..', 'sql', 'postgres_head.sql'))
17
+
18
+ config = Rails.configuration.database_configuration[Rails.env]
19
+
20
+ variables = {
21
+ db_name: config['database'],
22
+ user_name: config['username'],
23
+ }
24
+
25
+ variables.each_pair do |key, value|
26
+ safe_schema_head_sql = safe_schema_head_sql.gsub("s{#{key}}", value)
27
+ end
28
+
29
+ File.write('/tmp/refresh_db.sql', safe_schema_head_sql)
30
+
31
+ system("sudo -u postgres psql < /tmp/refresh_db.sql")
32
+ end
33
+
34
+
35
+ end
36
+
37
+ desc 'Refresh current cache'
38
+ task refresh_cache: :environment do
39
+ puts "Refresh with cache!"
40
+ end
41
+ end
42
+
43
+ desc 'Run default refresh task'
44
+ task :db_refresher => ['db_refresher:refresh']
data/refresher.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'refresher'
4
+ s.version = '0.1.0'
5
+ s.date = '2016-03-27'
6
+ s.summary = "db-refresher"
7
+ s.description = "Fast database prototyping with Rails"
8
+ s.authors = ["Mufid Afif"]
9
+ s.email = 'mufid@outlook.com'
10
+ s.files = [
11
+ 'refresher.gemspec',
12
+ ].concat( Dir.glob('lib/**/*').reject {|f| File.directory?(f) || f =~ /~$/ } )
13
+ # s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.homepage = 'https://github.com/mufid/refresher'
15
+ s.license = 'MIT'
16
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refresher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mufid Afif
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Fast database prototyping with Rails
14
+ email: mufid@outlook.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/refresher.rb
20
+ - lib/refresher/railtie.rb
21
+ - lib/sql/postgres_head.sql
22
+ - lib/tasks/db_refresher.rake
23
+ - refresher.gemspec
24
+ homepage: https://github.com/mufid/refresher
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.5.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: db-refresher
48
+ test_files: []