Add template model

This commit is contained in:
Trevor Vallender 2024-06-29 09:16:37 +01:00
parent e62578dc0d
commit 032c18d05d
3 changed files with 45 additions and 1 deletions

12
app/models/template.rb Normal file
View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
class Template < ApplicationRecord
belongs_to :game_system
validates :name, presence: true,
uniqueness: { scope: :game_system_id },
length: { maximum: 200 }
validates :content, presence: true
validates :klass, presence: true,
length: { maximum: 200 }
end

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
class CreateTemplates < ActiveRecord::Migration[7.1]
def change
create_table :templates do |t|
t.belongs_to :game_system, null: false, foreign_key: true
t.string :name, null: false
t.jsonb :content, null: false, default: {}
t.string :klass, null: false
t.timestamps
end
add_check_constraint :templates, "length(name) <= 200", name: "chk_template_name_max_length"
add_check_constraint :templates, "length(klass) <= 200", name: "chk_template_klass_max_length"
add_index :templates, [ :name, :game_system_id ], unique: true
end
end

16
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_06_21_141219) do
ActiveRecord::Schema[7.1].define(version: 2024_06_29_080930) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -283,6 +283,19 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_21_141219) do
t.check_constraint "length(slug::text) <= 100", name: "chk_table_slug_max_length"
end
create_table "templates", force: :cascade do |t|
t.bigint "game_system_id", null: false
t.string "name", null: false
t.jsonb "content", default: {}, null: false
t.string "klass", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["game_system_id"], name: "index_templates_on_game_system_id"
t.index ["name", "game_system_id"], name: "index_templates_on_name_and_game_system_id", unique: true
t.check_constraint "length(klass::text) <= 200", name: "chk_template_klass_max_length"
t.check_constraint "length(name::text) <= 200", name: "chk_template_name_max_length"
end
create_table "text_fields", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
@ -328,4 +341,5 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_21_141219) do
add_foreign_key "table_invites", "tables"
add_foreign_key "tables", "game_systems"
add_foreign_key "tables", "users", column: "owner_id"
add_foreign_key "templates", "game_systems"
end