Added Sequel migrations and models for videos and channels; Fixed database name in Rakefile and defaults config file
This commit is contained in:
parent
e731f6c84b
commit
646d2d19f9
2
.gitignore
vendored
2
.gitignore
vendored
@ -57,7 +57,7 @@ build-iPhoneSimulator/
|
||||
# .rubocop-https?--*
|
||||
|
||||
# Local database storage
|
||||
data/raven.db
|
||||
data/stgm.db
|
||||
|
||||
# Node modules for Grunt.js
|
||||
node_modules/
|
||||
|
@ -1,3 +1,3 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/raven.db'
|
||||
database: 'data/stgm.db'
|
||||
|
18
db/migrations/0001_add_channels_table.rb
Normal file
18
db/migrations/0001_add_channels_table.rb
Normal file
@ -0,0 +1,18 @@
|
||||
Sequel.migration do
|
||||
|
||||
up do
|
||||
create_table(:channels) do
|
||||
primary_key :id
|
||||
String :name, null: false
|
||||
String :description
|
||||
DateTime :purchased_at
|
||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
end
|
||||
end
|
||||
|
||||
down do
|
||||
drop_table(:channels)
|
||||
end
|
||||
|
||||
end
|
23
db/migrations/0002_add_videos_table.rb
Normal file
23
db/migrations/0002_add_videos_table.rb
Normal file
@ -0,0 +1,23 @@
|
||||
Sequel.migration do
|
||||
|
||||
up do
|
||||
create_table(:videos) do
|
||||
primary_key :id
|
||||
String :name, null: false
|
||||
String :description
|
||||
Integer :serial, null: false, unique: true
|
||||
DateTime :purchased_at
|
||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
end
|
||||
|
||||
alter_table(:videos) do
|
||||
add_foreign_key :channel_id, :channels
|
||||
end
|
||||
end
|
||||
|
||||
down do
|
||||
drop_table(:videos)
|
||||
end
|
||||
|
||||
end
|
5
lib/models/channel.rb
Normal file
5
lib/models/channel.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class Channel < Sequel::Model
|
||||
|
||||
one_to_many :videos
|
||||
|
||||
end
|
5
lib/models/video.rb
Normal file
5
lib/models/video.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class Video < Sequel::Model
|
||||
|
||||
many_to_one :channels
|
||||
|
||||
end
|
@ -1,14 +1,7 @@
|
||||
namespace '/' do
|
||||
|
||||
get '' do
|
||||
channels = [
|
||||
{
|
||||
:name => 'Bit Goblin',
|
||||
:openProjects => 'N/a',
|
||||
:totalProjects => 'N/a',
|
||||
:last_updated => 'N/a'
|
||||
}
|
||||
]
|
||||
channels = Channel.reverse(:updated_at).limit(10).all()
|
||||
erb :index, :locals => {
|
||||
:title => 'Dashboard',
|
||||
:channels => channels
|
||||
|
@ -22,7 +22,8 @@ Sequel::Model.plugin :timestamps
|
||||
# Initialize Sequel gem for database actions
|
||||
DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database'))
|
||||
# Load models
|
||||
# TODO - when models get made
|
||||
require_relative 'lib/models/channel.rb'
|
||||
require_relative 'lib/models/video.rb'
|
||||
|
||||
# Load helper functions
|
||||
require_relative 'lib/helpers.rb'
|
||||
|
@ -20,10 +20,10 @@
|
||||
<tbody>
|
||||
<% channels.each do |c| %>
|
||||
<tr>
|
||||
<td><%= c[:name] %></td>
|
||||
<td><%= c[:openProjects] %></td>
|
||||
<td><%= c[:totalProjects] %></td>
|
||||
<td><%= c[:last_updated] %></td>
|
||||
<td><%= c.name %></td>
|
||||
<td><%= nullable(c.openProjects) %></td>
|
||||
<td><%= nullable(c.videos.length) %></td>
|
||||
<td><%= date_format(c.last_updated) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user