From 7e2a71151bd3eeb5c84e1afe47ccf287622c73fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Mulet?= Date: Sat, 29 May 2021 18:45:32 +0200 Subject: [PATCH 1/4] Add social model --- apps/api/app/models/social.rb | 3 +++ .../db/migrate/20210529135425_create_socials.rb | 16 ++++++++++++++++ apps/api/test/fixtures/socials.yml | 11 +++++++++++ apps/api/test/models/social_test.rb | 7 +++++++ 4 files changed, 37 insertions(+) create mode 100644 apps/api/app/models/social.rb create mode 100644 apps/api/db/migrate/20210529135425_create_socials.rb create mode 100644 apps/api/test/fixtures/socials.yml create mode 100644 apps/api/test/models/social_test.rb diff --git a/apps/api/app/models/social.rb b/apps/api/app/models/social.rb new file mode 100644 index 00000000..90eb71f4 --- /dev/null +++ b/apps/api/app/models/social.rb @@ -0,0 +1,3 @@ +class Social < ApplicationRecord + +end 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 00000000..788c261b --- /dev/null +++ b/apps/api/db/migrate/20210529135425_create_socials.rb @@ -0,0 +1,16 @@ +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.timestamps + end + end + + def down + drop_table :socials + end +end diff --git a/apps/api/test/fixtures/socials.yml b/apps/api/test/fixtures/socials.yml new file mode 100644 index 00000000..2dbafdfa --- /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 00000000..0b9c6a18 --- /dev/null +++ b/apps/api/test/models/social_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class SocialTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 2f84e035d8e9e473df5a4cd70c09821e8eb18da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Mulet?= Date: Thu, 8 Jul 2021 19:21:07 +0200 Subject: [PATCH 2/4] Add social link to project & user --- apps/api/app/models/project.rb | 1 + apps/api/app/models/social.rb | 3 ++- apps/api/app/models/user.rb | 1 + .../db/migrate/20210529135425_create_socials.rb | 4 ++++ apps/api/db/schema.rb | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/api/app/models/project.rb b/apps/api/app/models/project.rb index d8d951f8..edf99f0a 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 index 90eb71f4..ed89123d 100644 --- a/apps/api/app/models/social.rb +++ b/apps/api/app/models/social.rb @@ -1,3 +1,4 @@ class Social < ApplicationRecord - + belongs_to :user + belongs_to :project end diff --git a/apps/api/app/models/user.rb b/apps/api/app/models/user.rb index 20f49cdc..ca8b6053 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 index 788c261b..d78585ba 100644 --- a/apps/api/db/migrate/20210529135425_create_socials.rb +++ b/apps/api/db/migrate/20210529135425_create_socials.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSocials < ActiveRecord::Migration[6.1] def up create_table :socials do |t| @@ -5,6 +7,8 @@ def up 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 diff --git a/apps/api/db/schema.rb b/apps/api/db/schema.rb index 62e618a9..64b48f89 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 From 9ccaac3d3a9c375213b53a946aca2e17b82d67a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Mulet?= Date: Thu, 8 Jul 2021 19:15:02 +0200 Subject: [PATCH 3/4] Fix auto-review --- apps/api/app/models/social.rb | 2 ++ apps/api/test/models/social_test.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/api/app/models/social.rb b/apps/api/app/models/social.rb index ed89123d..a8bc51e2 100644 --- a/apps/api/app/models/social.rb +++ b/apps/api/app/models/social.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Social < ApplicationRecord belongs_to :user belongs_to :project diff --git a/apps/api/test/models/social_test.rb b/apps/api/test/models/social_test.rb index 0b9c6a18..46cba836 100644 --- a/apps/api/test/models/social_test.rb +++ b/apps/api/test/models/social_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class SocialTest < ActiveSupport::TestCase # test "the truth" do From cbc7b5aa1838089f58d487a02d0f5fddd9d0eda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Mulet?= Date: Sat, 31 Jul 2021 23:11:30 +0200 Subject: [PATCH 4/4] Change social table to use polymorphic table --- apps/api/app/models/social.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/api/app/models/social.rb b/apps/api/app/models/social.rb index a8bc51e2..1098bd53 100644 --- a/apps/api/app/models/social.rb +++ b/apps/api/app/models/social.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true class Social < ApplicationRecord - belongs_to :user - belongs_to :project + belongs_to :socialable, polymorphic: true end