sinatra-activerecord 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -20
- data/lib/sinatra/activerecord.rb +1 -1
- data/lib/sinatra/activerecord/rake/activerecord_4.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c737e07b8e8d9daddeff819892c5ad278036564b
|
4
|
+
data.tar.gz: 797f41088003b92ec1d44edfbcb57b2a9df18132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a58243dc89f9e5faa22a5272950bc5cf007d29a5abbbacc70fc0ec5b93aa88ecf381cbb148984067802a9141fbe78ae5f06b4d1df7a3ce33b8ee5eef351e99
|
7
|
+
data.tar.gz: deca75897d21f51defb9f1ca72b610b201f2239972c6fd69b1f84792ee75229cf873ae6b617421828bf9db9fae33651806998285c54fe6cea36c2229383e9634
|
data/README.md
CHANGED
@@ -4,12 +4,6 @@ Extends [Sinatra](http://www.sinatrarb.com/) with extension methods and Rake
|
|
4
4
|
tasks for dealing with an SQL database using the
|
5
5
|
[ActiveRecord ORM](https://github.com/rails/rails/tree/master/activerecord).
|
6
6
|
|
7
|
-
## ActiveRecord 4.1
|
8
|
-
|
9
|
-
For ActiveRecord 4.1 use sinatra-activerecord `2.0.0.rc2`. I recommend upgrading
|
10
|
-
even if you don't use ActiveRecord 4.1, because it includes *all* the Rake tasks
|
11
|
-
that ActiveRecord has.
|
12
|
-
|
13
7
|
## Setup
|
14
8
|
|
15
9
|
Put it in your `Gemfile`, along with the adapter of your database. For
|
@@ -28,11 +22,13 @@ connection:
|
|
28
22
|
# app.rb
|
29
23
|
require "sinatra/activerecord"
|
30
24
|
|
31
|
-
set :database, "sqlite3
|
25
|
+
set :database, {adapter: "sqlite3", database: "foo.sqlite3"}
|
26
|
+
# or set :database_file, "path/to/database.yml"
|
32
27
|
```
|
33
28
|
|
34
|
-
|
35
|
-
|
29
|
+
If you have a `config/database.yml`, it will automatically be loaded, no need
|
30
|
+
to specify it. Also, in production, the `$DATABASE_URL` environment variable
|
31
|
+
will automatically be read as the database (if you haven't specified otherwise).
|
36
32
|
|
37
33
|
Note that in **modular** Sinatra applications you will need to first register
|
38
34
|
the extension:
|
@@ -55,17 +51,19 @@ In the Terminal test that it works:
|
|
55
51
|
|
56
52
|
```sh
|
57
53
|
$ rake -T
|
58
|
-
rake db:create
|
59
|
-
rake db:create_migration
|
60
|
-
rake db:drop
|
61
|
-
rake db:
|
62
|
-
rake db:migrate
|
63
|
-
rake db:
|
64
|
-
rake db:rollback
|
65
|
-
rake db:schema:dump
|
66
|
-
rake db:schema:load
|
67
|
-
rake db:seed
|
68
|
-
rake db:setup
|
54
|
+
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
|
55
|
+
rake db:create_migration # Create a migration (parameters: NAME, VERSION)
|
56
|
+
rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
|
57
|
+
rake db:fixtures:load # Load fixtures into the current environment's database
|
58
|
+
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false)
|
59
|
+
rake db:migrate:status # Display status of migrations
|
60
|
+
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
|
61
|
+
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
|
62
|
+
rake db:schema:load # Load a schema.rb file into the database
|
63
|
+
rake db:seed # Load the seed data from db/seeds.rb
|
64
|
+
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
65
|
+
rake db:structure:dump # Dump the database structure to db/structure.sql
|
66
|
+
rake db:version # Retrieves the current schema version number
|
69
67
|
```
|
70
68
|
|
71
69
|
And that's it, you're all set :)
|
data/lib/sinatra/activerecord.rb
CHANGED
@@ -18,7 +18,7 @@ module Sinatra
|
|
18
18
|
def self.registered(app)
|
19
19
|
app.set :database, ENV['DATABASE_URL'] if ENV['DATABASE_URL']
|
20
20
|
app.set :database_file, "#{Dir.pwd}/config/database.yml" if File.exists?("#{Dir.pwd}/config/database.yml")
|
21
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
21
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) unless defined?(Rake)
|
22
22
|
|
23
23
|
app.helpers ActiveRecordHelper
|
24
24
|
|
@@ -15,5 +15,6 @@ ActiveRecord::Tasks::DatabaseTasks.tap do |config|
|
|
15
15
|
config.database_configuration = ActiveRecord::Base.configurations
|
16
16
|
end
|
17
17
|
|
18
|
+
Rake::Task["db:load_config"].clear
|
18
19
|
Rake::Task.define_task("db:environment")
|
19
20
|
Rake::Task["db:test:deprecated"].clear if Rake::Task.task_defined?("db:test:deprecated")
|