migrake-sql_store 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ /pkg
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-19mode
6
+ env:
7
+ - RUBYOPT="$RUBYOPT -Itest -Ilib"
8
+ notifications:
9
+ email:
10
+ - contacto@nicolassanguinetti.info
data/CHANGES ADDED
@@ -0,0 +1,4 @@
1
+ 0.1.0 - April 15, 2012
2
+ ----------------------
3
+
4
+ Initial release! :party:
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,80 @@
1
+ # Migrake::SQLStore
2
+
3
+ [![Build Status](https://secure.travis-ci.org/foca/migrake-sql_store.png?branch=master)](http://travis-ci.org/foca/migrake-sql_store)
4
+
5
+ An extension for [Migrake][migrake] that stores the rake tasks that you ran in a
6
+ SQL database instead of the filesystem, useful for hosts like [Heroku][heroku]
7
+ where you have a read-only filesystem.
8
+
9
+ [migrake]: http://github.com/foca/migrake
10
+ [heroku]: http://heroku.com
11
+
12
+ ## Usage
13
+
14
+ In your Rakefile, instead of requiring `migrake`, require `migrake/sql_store`,
15
+ and initialize the store with the URI to your database:
16
+
17
+ ``` ruby
18
+ require "migrake/sql_store"
19
+
20
+ Migrake.store = Migrake::SQLStore.new("postgres://foo:foo@localhost/database")
21
+
22
+ migrake Set.new([
23
+ "some_rake_task",
24
+ "another_rake_task",
25
+ # etc, etc
26
+ ])
27
+ ```
28
+
29
+ When running `rake migrake` (or `rake migrake:ready`), SQLStore will check for a
30
+ `migrake_tasks` table. If it doesn't exist, it will create it transparently for
31
+ you.
32
+
33
+ This gem requires that you have the appropriate database adapter gems installed
34
+ and available (e.g. added to your Gemfile). If the target database is
35
+ postgresql, for example, make sure the `pg` is available in the environment
36
+ where `rake migrake` will be run.
37
+
38
+ ## Heroku (or other envs which include `DATABASE_URL`)
39
+
40
+ If your ENV includes a `DATABASE_URL`, you don't need to do anything, as
41
+ requiring `migrake/sql_store` will, by default, attempt to connect to a database
42
+ at that location, if the ENV key is set. So for Heroku, all you'd do is this:
43
+
44
+ ``` ruby
45
+ require "migrake/sql_store"
46
+
47
+ migrake Set.new([
48
+ "some_rake_task",
49
+ "another_rake_task",
50
+ # etc, etc
51
+ ])
52
+ ```
53
+
54
+ ## License
55
+
56
+ (The MIT License)
57
+
58
+ Copyright (c) 2012 [Nicolas Sanguinetti][me], with the support of [Cubox][cubox]
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining
61
+ a copy of this software and associated documentation files (the
62
+ 'Software'), to deal in the Software without restriction, including
63
+ without limitation the rights to use, copy, modify, merge, publish,
64
+ distribute, sublicense, and/or sell copies of the Software, and to
65
+ permit persons to whom the Software is furnished to do so, subject to
66
+ the following conditions:
67
+
68
+ The above copyright notice and this permission notice shall be
69
+ included in all copies or substantial portions of the Software.
70
+
71
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
72
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
73
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
74
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
75
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
76
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
77
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78
+
79
+ [me]: http://nicolassanguinetti.info
80
+ [cubox]: http://cuboxlabs.com
@@ -0,0 +1,15 @@
1
+ require "rake/testtask"
2
+ require "rubygems/package_task"
3
+
4
+ gem_spec = eval(File.read("./migrake-sql_store.gemspec"))
5
+ Gem::PackageTask.new(gem_spec) do |pkg|
6
+ pkg.need_zip = false
7
+ pkg.need_tar = false
8
+ end
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.pattern = "test/*_test.rb"
12
+ t.verbose = true
13
+ end
14
+
15
+ task default: :test
@@ -0,0 +1,55 @@
1
+ require "migrake"
2
+ require "sequel"
3
+ require "migrake/sql_store/version"
4
+
5
+ class Migrake::SQLStore
6
+ # Public: Connect to the database.
7
+ #
8
+ # db - Any valid argument to `Sequel.connect`.
9
+ def initialize(db)
10
+ @db = db.is_a?(Sequel::Database) ? db : Sequel.connect(db)
11
+ end
12
+
13
+ # Public: Make sure the table in which we will store tasks exists. Create it
14
+ # if it doesn't.
15
+ def prepare
16
+ @db.create_table?(:migrake_tasks) do
17
+ column :task, String, primary_key: true
18
+ end
19
+ end
20
+
21
+ # Public: Insert a task into the store.
22
+ #
23
+ # task - A string with a task's name.
24
+ #
25
+ # Returns nothing.
26
+ def put(task)
27
+ @db[:migrake_tasks].insert(task: task)
28
+ end
29
+
30
+ # Public: Load all the tasks from the store.
31
+ #
32
+ # Returns a Set.
33
+ def all
34
+ Set.new(@db[:migrake_tasks].map { |row| row[:task] })
35
+ end
36
+
37
+ # Public: Write a whole set of tasks to the database, replacing what is in it.
38
+ #
39
+ # set - A Set of tasks.
40
+ #
41
+ # Returns nothing.
42
+ def write(set)
43
+ @db.transaction do
44
+ @db[:migrake_tasks].truncate
45
+ @db[:migrake_tasks].insert_multiple(set.to_a) { |task| { task: task } }
46
+ end
47
+ end
48
+ end
49
+
50
+ # Automagic configuration. If this environment has a DATABASE_URL (e.g. heroku),
51
+ # use Migrake::SQLStore and connect to that database. This requires the
52
+ # appropriate database adapter installed.
53
+ if ENV.key?("DATABASE_URL")
54
+ Migrake.store = Migrake::SQLStore.new(ENV.fetch("DATABASE_URL"))
55
+ end
@@ -0,0 +1,5 @@
1
+ module Migrake
2
+ class SqlStore
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require "migrake/sql_store/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "migrake-sql_store"
5
+ s.version = Migrake::SqlStore::VERSION
6
+ s.description = "Migrake storage engine to use a SQL database instead of the filesystem"
7
+ s.summary = "SQL storage engine for Migrake"
8
+ s.authors = ["Nicolas Sanguinetti"]
9
+ s.email = "hi@nicolassanguinetti.info"
10
+ s.homepage = "http://github.com/foca/migrake-sql_store"
11
+ s.has_rdoc = false
12
+ s.files = `git ls-files`.split "\n"
13
+ s.platform = Gem::Platform::RUBY
14
+
15
+ s.add_dependency("migrake", "~> 0.2")
16
+ s.add_dependency("sequel", "~> 3.34")
17
+ s.add_development_dependency("minitest")
18
+ s.add_development_dependency("sqlite3")
19
+ end
@@ -0,0 +1,66 @@
1
+ require_relative "test_helper"
2
+
3
+ describe Migrake::SQLStore do
4
+ it "can read a stored set" do
5
+ create_migrake_table!
6
+
7
+ set = Set.new(["a", "b", "c"])
8
+ save_in_source set
9
+
10
+ store = Migrake::SQLStore.new(source)
11
+ assert_equal set, store.all
12
+ end
13
+
14
+ it "an empty file means an empty set" do
15
+ create_migrake_table!
16
+
17
+ store = Migrake::SQLStore.new(source)
18
+ assert_equal Set.new, store.all
19
+ end
20
+
21
+ it "can add an entry to the store" do
22
+ create_migrake_table!
23
+
24
+ store = Migrake::SQLStore.new(source)
25
+ store.put("test")
26
+
27
+ assert store.all.include?("test")
28
+ end
29
+
30
+ it "can write a set replacing whatever is there on the file" do
31
+ create_migrake_table!
32
+
33
+ save_in_source Set.new(["d", "e", "f", "g"])
34
+
35
+ store = Migrake::SQLStore.new(source)
36
+ store.write Set.new(["a", "b", "c"])
37
+
38
+ assert_equal Set.new(["a", "b", "c"]), store.all
39
+ end
40
+
41
+ it "creates the migrake_tasks when you call #prepare" do
42
+ store = Migrake::SQLStore.new(source)
43
+
44
+ assert !source.table_exists?(:migrake_tasks)
45
+ store.prepare
46
+ assert source.table_exists?(:migrake_tasks)
47
+ end
48
+
49
+ before do
50
+ source.drop_table?(:migrake_tasks)
51
+ end
52
+
53
+ def save_in_source(set)
54
+ source[:migrake_tasks].insert_multiple(set) { |task| { task: task } }
55
+ end
56
+
57
+ def source
58
+ @source ||= Sequel.sqlite
59
+ end
60
+
61
+ def create_migrake_table!(db = source)
62
+ db.create_table?(:migrake_tasks) do
63
+ column :task, String, primary_key: true
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,9 @@
1
+ require "minitest/autorun"
2
+ require "migrake/sql_store"
3
+
4
+ begin
5
+ require "purdytest"
6
+ rescue LoadError
7
+ # Oh well, no colorized tests for you. You can always use minitest/pride if
8
+ # you want :P
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migrake-sql_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicolas Sanguinetti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: migrake
16
+ requirement: &70145851982360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70145851982360
25
+ - !ruby/object:Gem::Dependency
26
+ name: sequel
27
+ requirement: &70145851981860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.34'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70145851981860
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70145851997840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70145851997840
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: &70145851997380 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70145851997380
58
+ description: Migrake storage engine to use a SQL database instead of the filesystem
59
+ email: hi@nicolassanguinetti.info
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - .travis.yml
66
+ - CHANGES
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - lib/migrake/sql_store.rb
71
+ - lib/migrake/sql_store/version.rb
72
+ - migrake-sql_store.gemspec
73
+ - test/sql_store_test.rb
74
+ - test/test_helper.rb
75
+ homepage: http://github.com/foca/migrake-sql_store
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.11
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: SQL storage engine for Migrake
99
+ test_files: []