parent
61dfdcbcd4
commit
5864e3f464
@ -1,3 +1,13 @@
|
||||
require "./lib/app"
|
||||
App.freeze unless ENV["RACK_ENV"] == "development"
|
||||
run App.app
|
||||
dev = ENV["RACK_ENV"] == "development"
|
||||
|
||||
if dev
|
||||
require "logger"
|
||||
logger = Logger.new($stdout)
|
||||
end
|
||||
|
||||
|
||||
require "rack/unreloader"
|
||||
Unreloader = Rack::Unreloader.new(subclasses: %w[Roda Sequel::Model], logger: logger, reload: dev, autoload: dev){App}
|
||||
require_relative "lib/models"
|
||||
Unreloader.require("lib/app.rb"){'App'}
|
||||
run(dev ? Unreloader : App.freeze.app)
|
||||
|
@ -0,0 +1,3 @@
|
||||
require "sequel/core"
|
||||
|
||||
DB = Sequel.connect(ENV.delete("DATABASE_URL"))
|
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "db"
|
||||
require "sequel/model"
|
||||
|
||||
if ENV["RACK_ENV"] == "development"
|
||||
Sequel::Model.cache_associations = false
|
||||
end
|
||||
|
||||
Sequel::Model.plugin :auto_validations
|
||||
Sequel::Model.plugin :require_valid_schema
|
||||
Sequel::Model.plugin :subclasses unless ENV["RACK_ENV"] == "development"
|
||||
|
||||
unless defined?(Unreloader)
|
||||
require "rack/unreloader"
|
||||
Unreloader = Rack::Unreloader.new(reload: false, autoload: !ENV["NO_AUTOLOAD"])
|
||||
end
|
||||
|
||||
Unreloader.autoload("models"){|f| Sequel::Model.send(:camelize, File.basename(f).sub(/\.rb\z/, ''))}
|
||||
|
||||
if ENV["RACK_ENV"] == "development" || ENV["RACK_ENV"] == "test"
|
||||
require "logger"
|
||||
LOGGER = Logger.new($stdout)
|
||||
LOGGER.level = Logger::FATAL if ENV["RACK_ENV"] == "test"
|
||||
DB.loggers << LOGGER
|
||||
end
|
@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Sequel.migration do
|
||||
change do
|
||||
create_table(:pools) do
|
||||
primary_key :id
|
||||
|
||||
String :name, null: false
|
||||
|
||||
DateTime :created_at, null: false
|
||||
DateTime :updated_at, null: false
|
||||
end
|
||||
|
||||
create_table(:items) do
|
||||
primary_key :id
|
||||
|
||||
foreign_key :pool_id, :pools, null: false
|
||||
|
||||
String :title, null: false
|
||||
String :body, null: false
|
||||
|
||||
DateTime :created_at, null: false
|
||||
DateTime :updated_at, null: false
|
||||
end
|
||||
|
||||
create_table(:axes) do
|
||||
primary_key :id
|
||||
|
||||
foreign_key :pool_id, :pools, null: false
|
||||
|
||||
String :name, null: false
|
||||
String :better_legend, null: false
|
||||
String :worse_legend, null: false
|
||||
|
||||
DateTime :created_at, null: false
|
||||
DateTime :updated_at, null: false
|
||||
end
|
||||
|
||||
create_table(:ratings) do
|
||||
primary_key :id
|
||||
|
||||
foreign_key :axis_id, :axes, null: false
|
||||
foreign_key :winner_id, :items, null: false
|
||||
foreign_key :loser_id, :items, null: false
|
||||
|
||||
DateTime :created_at, null: false
|
||||
DateTime :updated_at, null: false
|
||||
end
|
||||
|
||||
create_table(:rankings) do
|
||||
primary_key :id
|
||||
|
||||
foreign_key :axis_id, :axes, null: false
|
||||
foreign_key :item_id, :items, null: false
|
||||
|
||||
float :mu, null: false
|
||||
float :sigma, null: false
|
||||
|
||||
DateTime :created_at, null: false
|
||||
DateTime :updated_at, null: false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue