diff --git a/app/models/template.rb b/app/models/template.rb new file mode 100644 index 0000000..0e31f51 --- /dev/null +++ b/app/models/template.rb @@ -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 diff --git a/db/migrate/20240629080930_create_templates.rb b/db/migrate/20240629080930_create_templates.rb new file mode 100644 index 0000000..4c2f480 --- /dev/null +++ b/db/migrate/20240629080930_create_templates.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 9f286eb..b7c8f38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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