Skip to content
Merged
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
13 changes: 13 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Team < ApplicationRecord
# == Schema Information
#
# Table name: teams
#
# id :bigint(8) not null, primary key
# name :string not null
#
# Indexes
#
# teams_name_idx (name) UNIQUE
#
end
20 changes: 20 additions & 0 deletions app/models/team_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: team_user
#
# team_id :bigint(8) not null, primary key
# user_id :bigint(8) not null, primary key
#
# Indexes
#
# team_id_user_id_unique (team_id,user_id) UNIQUE
#
# Foreign Keys
#
# team_id_fkey (team_id => teams.id)
# user_id_fkey (user_id => users.id)
#
class TeamUser < ApplicationRecord
belongs_to :team
belongs_to :user
end
25 changes: 25 additions & 0 deletions db/migrate/20251028201000_create_team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class CreateTeam < ActiveRecord::Migration[7.1]
def up
create_table :teams do |t|
t.bigint :workspace_id
t.string :name
end

add_index :teams, [:workspace_id, :name], unique: true

create_table :team_user, id: false do |t|
t.bigint :team_id, null: false
t.bigint :user_id, null: false
end

add_index :team_user, [:team_id, :user_id], unique: true

add_foreign_key :team_user, :teams, column: :team_id, validate: false
add_foreign_key :team_user, :users, column: :user_id, validate: false
end

def down
drop_table :team_user
drop_table :teams
end
end
Loading