diff --git a/apps/api/app/models/project.rb b/apps/api/app/models/project.rb index d8d951f..edf99f0 100644 --- a/apps/api/app/models/project.rb +++ b/apps/api/app/models/project.rb @@ -6,6 +6,7 @@ class Project < ApplicationRecord has_many_attached :screenshots has_one_attached :avatar has_many :webhooks, dependent: :destroy + has_many :socials, dependent: :destroy validates :name, presence: true, length: { minimum: 2, maximum: 32 }, profanity: true validates :slug, presence: true, uniqueness: true, length: { minimum: 2, maximum: 32 }, profanity: true diff --git a/apps/api/app/models/social.rb b/apps/api/app/models/social.rb new file mode 100644 index 0000000..1098bd5 --- /dev/null +++ b/apps/api/app/models/social.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Social < ApplicationRecord + belongs_to :socialable, polymorphic: true +end diff --git a/apps/api/app/models/user.rb b/apps/api/app/models/user.rb index 20f49cd..ca8b605 100644 --- a/apps/api/app/models/user.rb +++ b/apps/api/app/models/user.rb @@ -13,6 +13,7 @@ class User < ApplicationRecord has_many :streaks, dependent: :destroy has_many :projects, dependent: :destroy has_many :webhooks, dependent: :destroy + has_many :socials, dependent: :destroy has_one :email_notification, dependent: :destroy has_and_belongs_to_many :mentions, class_name: 'Task', join_table: 'task_mentions' diff --git a/apps/api/db/migrate/20210529135425_create_socials.rb b/apps/api/db/migrate/20210529135425_create_socials.rb new file mode 100644 index 0000000..d78585b --- /dev/null +++ b/apps/api/db/migrate/20210529135425_create_socials.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreateSocials < ActiveRecord::Migration[6.1] + def up + create_table :socials do |t| + t.uuid :uuid, index: { unique: true }, default: 'gen_random_uuid()', null: false + t.string :name, index: { unique: true }, null: false + t.string :title + t.string :url, null: false + t.references :user, index: true, null: true + t.references :project, index: true, null: true + + t.timestamps + end + end + + def down + drop_table :socials + end +end diff --git a/apps/api/db/schema.rb b/apps/api/db/schema.rb index 62e618a..64b48f8 100644 --- a/apps/api/db/schema.rb +++ b/apps/api/db/schema.rb @@ -118,6 +118,21 @@ t.index ["task_id"], name: "index_projects_tasks_on_task_id" end + create_table "socials", force: :cascade do |t| + t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false + t.string "name", null: false + t.string "title" + t.string "url", null: false + t.bigint "user_id" + t.bigint "project_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["name"], name: "index_socials_on_name", unique: true + t.index ["project_id"], name: "index_socials_on_project_id" + t.index ["user_id"], name: "index_socials_on_user_id" + t.index ["uuid"], name: "index_socials_on_uuid", unique: true + end + create_table "streaks", force: :cascade do |t| t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false t.bigint "user_id", null: false diff --git a/apps/api/test/fixtures/socials.yml b/apps/api/test/fixtures/socials.yml new file mode 100644 index 0000000..2dbafdf --- /dev/null +++ b/apps/api/test/fixtures/socials.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + title: MyString + url: MyString + +two: + name: MyString + title: MyString + url: MyString diff --git a/apps/api/test/models/social_test.rb b/apps/api/test/models/social_test.rb new file mode 100644 index 0000000..46cba83 --- /dev/null +++ b/apps/api/test/models/social_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'test_helper' + +class SocialTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end