Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 26 additions & 0 deletions db/migrate/20251028201000_create_team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class CreateTeam < ActiveRecord::Migration[7.1]
def up
create_table :teams, primary_key: :id do |t|
t.integer :id
t.integer :workspace_id
t.string :name
end

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

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

add_index :team_user, [:team_id, :user_id], unique: true
add_foreign_key :team_user, :teams, column: :team_id
add_foreign_key :team_user, :users, column: :user_id
end

def down
drop_table :team_user
drop_table :teams
end
end
Loading