Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions apps/api/app/models/social.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Social < ApplicationRecord
belongs_to :socialable, polymorphic: true
end
1 change: 1 addition & 0 deletions apps/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
20 changes: 20 additions & 0 deletions apps/api/db/migrate/20210529135425_create_socials.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions apps/api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions apps/api/test/fixtures/socials.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions apps/api/test/models/social_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class SocialTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end