diff --git a/app/models/team.rb b/app/models/team.rb new file mode 100644 index 0000000000..a836bd3595 --- /dev/null +++ b/app/models/team.rb @@ -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 diff --git a/app/models/team_user.rb b/app/models/team_user.rb new file mode 100644 index 0000000000..410fed7f0c --- /dev/null +++ b/app/models/team_user.rb @@ -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 diff --git a/db/migrate/20251028201000_create_team.rb b/db/migrate/20251028201000_create_team.rb new file mode 100644 index 0000000000..24dc05f08d --- /dev/null +++ b/db/migrate/20251028201000_create_team.rb @@ -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