Browse Source

ajout du model Team, et d'une join table team_user

Lou 3 years ago
parent
commit
5e40cd0387

+ 2
- 0
app/models/team.rb View File

@@ -0,0 +1,2 @@
1
+class Team < ApplicationRecord
2
+end

+ 11
- 0
db/migrate/20210803144838_create_teams.rb View File

@@ -0,0 +1,11 @@
1
+class CreateTeams < ActiveRecord::Migration[6.1]
2
+  def change
3
+    create_table :teams do |t|
4
+      t.string :name, null: false
5
+      t.index :name, unique: true
6
+      t.text :description
7
+
8
+      t.timestamps
9
+    end
10
+  end
11
+end

+ 8
- 0
db/migrate/20210803145424_create_teams_users_join_table.rb View File

@@ -0,0 +1,8 @@
1
+class CreateTeamsUsersJoinTable < ActiveRecord::Migration[6.1]
2
+  def change
3
+    create_join_table :teams, :users do |t|
4
+      t.index :team_id
5
+      t.index :user_id
6
+    end
7
+  end
8
+end

+ 16
- 1
db/schema.rb View File

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 2021_05_10_133939) do
13
+ActiveRecord::Schema.define(version: 2021_08_03_145424) do
14 14
 
15 15
   # These are extensions that must be enabled in order to support this database
16 16
   enable_extension "plpgsql"
@@ -48,6 +48,21 @@ ActiveRecord::Schema.define(version: 2021_05_10_133939) do
48 48
     t.index ["user_id"], name: "index_tasks_on_user_id"
49 49
   end
50 50
 
51
+  create_table "teams", force: :cascade do |t|
52
+    t.string "name", null: false
53
+    t.text "description"
54
+    t.datetime "created_at", precision: 6, null: false
55
+    t.datetime "updated_at", precision: 6, null: false
56
+    t.index ["name"], name: "index_teams_on_name", unique: true
57
+  end
58
+
59
+  create_table "teams_users", id: false, force: :cascade do |t|
60
+    t.bigint "team_id", null: false
61
+    t.bigint "user_id", null: false
62
+    t.index ["team_id"], name: "index_teams_users_on_team_id"
63
+    t.index ["user_id"], name: "index_teams_users_on_user_id"
64
+  end
65
+
51 66
   create_table "users", force: :cascade do |t|
52 67
     t.string "email", null: false
53 68
     t.string "username", null: false

+ 5
- 0
test/fixtures/teams.yml View File

@@ -0,0 +1,5 @@
1
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+one:
4
+  name: MyString
5
+  description: MyText

+ 7
- 0
test/models/team_test.rb View File

@@ -0,0 +1,7 @@
1
+require "test_helper"
2
+
3
+class TeamTest < ActiveSupport::TestCase
4
+  # test "the truth" do
5
+  #   assert true
6
+  # end
7
+end

Loading…
Cancel
Save