Skip to content

Commit 0612a27

Browse files
authored
Merge pull request #48 from TaskarCenterAtUW/2442-team-db-migrate
activerecords for team and team_user
2 parents 10519ae + 8379e75 commit 0612a27

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

app/models/team.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Team < ApplicationRecord
2+
# == Schema Information
3+
#
4+
# Table name: teams
5+
#
6+
# id :bigint(8) not null, primary key
7+
# name :string not null
8+
#
9+
# Indexes
10+
#
11+
# teams_name_idx (name) UNIQUE
12+
#
13+
end

app/models/team_user.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# == Schema Information
2+
#
3+
# Table name: team_user
4+
#
5+
# team_id :bigint(8) not null, primary key
6+
# user_id :bigint(8) not null, primary key
7+
#
8+
# Indexes
9+
#
10+
# team_id_user_id_unique (team_id,user_id) UNIQUE
11+
#
12+
# Foreign Keys
13+
#
14+
# team_id_fkey (team_id => teams.id)
15+
# user_id_fkey (user_id => users.id)
16+
#
17+
class TeamUser < ApplicationRecord
18+
belongs_to :team
19+
belongs_to :user
20+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class CreateTeam < ActiveRecord::Migration[7.1]
2+
def up
3+
create_table :teams do |t|
4+
t.bigint :workspace_id
5+
t.string :name
6+
end
7+
8+
add_index :teams, [:workspace_id, :name], unique: true
9+
10+
create_table :team_user, id: false do |t|
11+
t.bigint :team_id, null: false
12+
t.bigint :user_id, null: false
13+
end
14+
15+
add_index :team_user, [:team_id, :user_id], unique: true
16+
17+
add_foreign_key :team_user, :teams, column: :team_id, validate: false
18+
add_foreign_key :team_user, :users, column: :user_id, validate: false
19+
end
20+
21+
def down
22+
drop_table :team_user
23+
drop_table :teams
24+
end
25+
end

0 commit comments

Comments
 (0)