Fix compile errors in seed script, ensure it is compiled on CI

Co-authored-by: Nate Butler <nate@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-11-14 11:12:25 -08:00
parent 0dcdd6ea39
commit 6659dac2e5
2 changed files with 10 additions and 70 deletions

View file

@ -49,7 +49,7 @@ jobs:
run: cargo build -p collab
- name: Build other binaries
run: cargo build --bins --all-features
run: cargo build --workspace --bins --all-features
bundle:
name: Bundle app

View file

@ -1,9 +1,7 @@
use collab::{Error, Result};
use db::{Db, PostgresDb, UserId};
use rand::prelude::*;
use db::DefaultDb;
use serde::{de::DeserializeOwned, Deserialize};
use std::fmt::Write;
use time::{Duration, OffsetDateTime};
#[allow(unused)]
#[path = "../db.rs"]
@ -18,9 +16,8 @@ struct GitHubUser {
#[tokio::main]
async fn main() {
let mut rng = StdRng::from_entropy();
let database_url = std::env::var("DATABASE_URL").expect("missing DATABASE_URL env var");
let db = PostgresDb::new(&database_url, 5)
let db = DefaultDb::new(&database_url, 5)
.await
.expect("failed to connect to postgres database");
let github_token = std::env::var("GITHUB_TOKEN").expect("missing GITHUB_TOKEN env var");
@ -64,16 +61,14 @@ async fn main() {
}
}
let mut zed_user_ids = Vec::<UserId>::new();
for (github_user, admin) in zed_users {
if let Some(user) = db
if db
.get_user_by_github_account(&github_user.login, Some(github_user.id))
.await
.expect("failed to fetch user")
.is_none()
{
zed_user_ids.push(user.id);
} else if let Some(email) = &github_user.email {
zed_user_ids.push(
if let Some(email) = &github_user.email {
db.create_user(
email,
admin,
@ -84,11 +79,8 @@ async fn main() {
},
)
.await
.expect("failed to insert user")
.user_id,
);
} else if admin {
zed_user_ids.push(
.expect("failed to insert user");
} else if admin {
db.create_user(
&format!("{}@zed.dev", github_user.login),
admin,
@ -99,62 +91,10 @@ async fn main() {
},
)
.await
.expect("failed to insert user")
.user_id,
);
.expect("failed to insert user");
}
}
}
let zed_org_id = if let Some(org) = db
.find_org_by_slug("zed")
.await
.expect("failed to fetch org")
{
org.id
} else {
db.create_org("Zed", "zed")
.await
.expect("failed to insert org")
};
let general_channel_id = if let Some(channel) = db
.get_org_channels(zed_org_id)
.await
.expect("failed to fetch channels")
.iter()
.find(|c| c.name == "General")
{
channel.id
} else {
let channel_id = db
.create_org_channel(zed_org_id, "General")
.await
.expect("failed to insert channel");
let now = OffsetDateTime::now_utc();
let max_seconds = Duration::days(100).as_seconds_f64();
let mut timestamps = (0..1000)
.map(|_| now - Duration::seconds_f64(rng.gen_range(0_f64..=max_seconds)))
.collect::<Vec<_>>();
timestamps.sort();
for timestamp in timestamps {
let sender_id = *zed_user_ids.choose(&mut rng).unwrap();
let body = lipsum::lipsum_words(rng.gen_range(1..=50));
db.create_channel_message(channel_id, sender_id, &body, timestamp, rng.gen())
.await
.expect("failed to insert message");
}
channel_id
};
for user_id in zed_user_ids {
db.add_org_member(zed_org_id, user_id, true)
.await
.expect("failed to insert org membership");
db.add_channel_member(general_channel_id, user_id, true)
.await
.expect("failed to insert channel membership");
}
}
async fn fetch_github<T: DeserializeOwned>(