Skip to content

Commit d8fec9a

Browse files
committed
update team invite schema
1 parent f8feece commit d8fec9a

7 files changed

Lines changed: 98 additions & 85 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rand = "0.8.4"
1515
regex = "1.5.4"
1616
reqwest = {version = "0.11.6", features = ["json"]}
1717
time = "0.2.25"
18+
nanoid = "0.4.0"
1819

1920
tokio = {version = "1.15.0", features = ["full"]}
2021

crates/db_models/src/schema.rs

Lines changed: 76 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,97 @@
11
table! {
2-
apps (id) {
3-
id -> Int4,
4-
created_at -> Timestamp,
5-
slug -> Text,
6-
team_id -> Int4,
7-
enabled -> Bool,
8-
container_id -> Nullable<Text>,
9-
network_id -> Nullable<Text>,
10-
}
2+
apps (id) {
3+
id -> Int4,
4+
created_at -> Timestamp,
5+
slug -> Text,
6+
team_id -> Int4,
7+
enabled -> Bool,
8+
container_id -> Nullable<Text>,
9+
network_id -> Nullable<Text>,
10+
}
1111
}
1212

1313
table! {
14-
builds (id) {
15-
id -> Int4,
16-
started_at -> Timestamp,
17-
ended_at -> Nullable<Timestamp>,
18-
events -> Array<Text>,
19-
app_id -> Int4,
20-
}
14+
builds (id) {
15+
id -> Int4,
16+
started_at -> Timestamp,
17+
ended_at -> Nullable<Timestamp>,
18+
events -> Array<Text>,
19+
app_id -> Int4,
20+
}
2121
}
2222

2323
table! {
24-
domains (id) {
25-
id -> Int4,
26-
domain -> Text,
27-
verified -> Bool,
28-
app_id -> Int4,
29-
}
24+
domains (id) {
25+
id -> Int4,
26+
domain -> Text,
27+
verified -> Bool,
28+
app_id -> Int4,
29+
}
3030
}
3131

3232
table! {
33-
oauth_apps (client_id) {
34-
client_id -> Text,
35-
name -> Text,
36-
}
33+
oauth_apps (client_id) {
34+
client_id -> Text,
35+
name -> Text,
36+
}
3737
}
3838

3939
table! {
40-
oauth_device_requests (id) {
41-
id -> Int4,
42-
created_at -> Timestamp,
43-
expires_at -> Timestamp,
44-
oauth_app_id -> Text,
45-
token -> Nullable<Text>,
46-
device_code -> Text,
47-
user_code -> Text,
48-
token_retrieved -> Bool,
49-
access_denied -> Bool,
50-
}
40+
oauth_device_requests (id) {
41+
id -> Int4,
42+
created_at -> Timestamp,
43+
expires_at -> Timestamp,
44+
oauth_app_id -> Text,
45+
token -> Nullable<Text>,
46+
device_code -> Text,
47+
user_code -> Text,
48+
token_retrieved -> Bool,
49+
access_denied -> Bool,
50+
}
5151
}
5252

5353
table! {
54-
team_users (team_id, user_id) {
55-
user_id -> Int4,
56-
team_id -> Int4,
57-
}
54+
team_users (team_id, user_id) {
55+
user_id -> Int4,
56+
team_id -> Int4,
57+
}
5858
}
5959

6060
table! {
61-
invites (team_id, user_id) {
62-
user_id -> Int4,
63-
team_id -> Int4,
64-
}
61+
teams (id) {
62+
id -> Int4,
63+
created_at -> Timestamp,
64+
name -> Nullable<Text>,
65+
avatar -> Nullable<Text>,
66+
personal -> Bool,
67+
slug -> Text,
68+
invite -> Text,
69+
}
6570
}
6671

6772
table! {
68-
teams (id) {
69-
id -> Int4,
70-
created_at -> Timestamp,
71-
name -> Nullable<Text>,
72-
avatar -> Nullable<Text>,
73-
personal -> Bool,
74-
slug -> Text,
75-
}
73+
tokens (token) {
74+
token -> Text,
75+
created_at -> Timestamp,
76+
expires_at -> Timestamp,
77+
user_id -> Int4,
78+
}
7679
}
7780

7881
table! {
79-
tokens (token) {
80-
token -> Text,
81-
created_at -> Timestamp,
82-
expires_at -> Timestamp,
83-
user_id -> Int4,
84-
}
82+
users (id) {
83+
id -> Int4,
84+
created_at -> Timestamp,
85+
slack_user_id -> Text,
86+
name -> Text,
87+
avatar -> Nullable<Text>,
88+
}
8589
}
8690

8791
table! {
88-
users (id) {
89-
id -> Int4,
90-
created_at -> Timestamp,
91-
slack_user_id -> Text,
92-
name -> Text,
93-
avatar -> Nullable<Text>,
94-
}
95-
}
96-
97-
table! {
98-
whitelist (slack_user_id) {
99-
slack_user_id -> Text,
100-
}
92+
whitelist (slack_user_id) {
93+
slack_user_id -> Text,
94+
}
10195
}
10296

10397
joinable!(apps -> teams (team_id));
@@ -107,19 +101,17 @@ joinable!(oauth_device_requests -> oauth_apps (oauth_app_id));
107101
joinable!(oauth_device_requests -> tokens (token));
108102
joinable!(team_users -> teams (team_id));
109103
joinable!(team_users -> users (user_id));
110-
joinable!(invites -> teams (team_id));
111-
joinable!(invites -> users (user_id));
112104
joinable!(tokens -> users (user_id));
113105

114106
allow_tables_to_appear_in_same_query!(
115-
apps,
116-
builds,
117-
domains,
118-
oauth_apps,
119-
oauth_device_requests,
120-
team_users,
121-
teams,
122-
tokens,
123-
users,
124-
whitelist,
107+
apps,
108+
builds,
109+
domains,
110+
oauth_apps,
111+
oauth_device_requests,
112+
team_users,
113+
teams,
114+
tokens,
115+
users,
116+
whitelist,
125117
);

crates/db_models/src/team.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Team {
1111
pub avatar: Option<String>,
1212
pub personal: bool,
1313
pub slug: String,
14+
pub invite: String,
1415
}
1516

1617
#[derive(Clone, Debug, Insertable, Deserialize)]
@@ -21,6 +22,7 @@ pub struct NewTeam {
2122
#[serde(skip_deserializing)]
2223
pub personal: bool,
2324
pub slug: String,
25+
pub invite: String,
2426
}
2527

2628
#[derive(Clone, Debug, AsChangeset, Deserialize)]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE teams DROP COLUMN invite
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Your SQL goes here
2+
ALTER TABLE teams
3+
ADD COLUMN invite TEXT NOT NULL UNIQUE

src/api/teams.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ use db_models::{App, NewTeam, Team, TeamUser, UpdatedTeam, User};
1212

1313
use crate::{auth::AuthUser, utils::slug::validate_slug, DbConn};
1414

15+
use nanoid::nanoid;
16+
1517
/// Fetches a team by the `slug`, which can either be a Team.slug or a numeric Team.id
1618
fn fetch_team(team_slug: String, user_id: i32, c: &diesel::PgConnection) -> QueryResult<Team> {
1719
use db_models::schema::team_users;
1820
use db_models::schema::teams::dsl::*;
19-
2021
// Attempt to parse out a numeric ID
2122
let team = match team_slug.parse::<i32>() {
2223
Ok(i) => teams
@@ -48,6 +49,8 @@ pub async fn create(
4849
use db_models::schema::team_users::dsl::*;
4950
use db_models::schema::teams::dsl::*;
5051

52+
let inv_id = nanoid!(7);
53+
5154
let created_team = diesel::insert_into(teams)
5255
.values(team.0)
5356
.get_result::<Team>(c)

0 commit comments

Comments
 (0)