diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..f814dbf --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +set -a +source .env +set +a \ No newline at end of file diff --git a/migrations/20250626163902_bank.sql b/migrations/20250626163902_bank.sql new file mode 100644 index 0000000..2c8c360 --- /dev/null +++ b/migrations/20250626163902_bank.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS bank ( + id BIGINT PRIMARY KEY, + balance INT +) diff --git a/migrations/20250626164104_selfroles.sql b/migrations/20250626164104_selfroles.sql new file mode 100644 index 0000000..291e2ad --- /dev/null +++ b/migrations/20250626164104_selfroles.sql @@ -0,0 +1,8 @@ + +CREATE TABLE IF NOT EXISTS selfroles ( + userid BIGINT NOT NULL, + guildid BIGINT NOT NULL, + roleid BIGINT, + UNIQUE (userid, guildid) +) + diff --git a/migrations/20250626164333_games.sql b/migrations/20250626164333_games.sql new file mode 100644 index 0000000..cf58397 --- /dev/null +++ b/migrations/20250626164333_games.sql @@ -0,0 +1,6 @@ + +CREATE TABLE IF NOT EXISTS games ( + id BIGSERIAL PRIMARY KEY, + name CHAR[255] +) + diff --git a/migrations/20250626164633_items.sql b/migrations/20250626164633_items.sql new file mode 100644 index 0000000..476ab76 --- /dev/null +++ b/migrations/20250626164633_items.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS items ( + id BIGSERIAL PRIMARY KEY, + owner BIGINT NOT NULL, + game BIGINT NOT NULL, + item BIGINT NOT NULL, + data JSON NOT NULL, + name TEXT +) diff --git a/migrations/20250626164737_dailies.sql b/migrations/20250626164737_dailies.sql new file mode 100644 index 0000000..b428c91 --- /dev/null +++ b/migrations/20250626164737_dailies.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS dailies ( + userid BIGINT NOT NULL PRIMARY KEY, + last TIMESTAMPTZ, + streak INT +) diff --git a/migrations/20250626164817_settings.sql b/migrations/20250626164817_settings.sql new file mode 100644 index 0000000..47cdca0 --- /dev/null +++ b/migrations/20250626164817_settings.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS settings ( + guildid BIGINT NOT NULL PRIMARY KEY, + positional_role BIGINT, + banrole BIGINT, + hoist_selfroles BOOLEAN, + prefix TEXT +) diff --git a/src/main.rs b/src/main.rs index 6b1c045..1a834cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,69 +111,9 @@ async fn main() -> Result<(), Error> { .max_connections(5) .connect(&database_url).await?; - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS bank ( - id BIGINT PRIMARY KEY, - balance INT - ) - "#, - ).execute(&database).await?; - - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS selfroles ( - userid BIGINT NOT NULL, - guildid BIGINT NOT NULL, - roleid BIGINT, - UNIQUE (userid, guildid) - ) - "#, - ).execute(&database).await?; - - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS games ( - id BIGSERIAL PRIMARY KEY, - name CHAR[255] - ) - "# - ).execute(&database).await?; - - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS items ( - id BIGSERIAL PRIMARY KEY, - owner BIGINT NOT NULL, - game BIGINT NOT NULL, - item BIGINT NOT NULL, - data JSON NOT NULL, - name TEXT - ) - "# - ).execute(&database).await?; - - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS dailies ( - userid BIGINT NOT NULL PRIMARY KEY, - last TIMESTAMPTZ, - streak INT - ) - "# - ).execute(&database).await?; - - sqlx::query( - r#" - CREATE TABLE IF NOT EXISTS settings ( - guildid BIGINT NOT NULL PRIMARY KEY, - positional_role BIGINT, - banrole BIGINT, - hoist_selfroles BOOLEAN, - prefix TEXT - ) - "# - ).execute(&database).await?; + sqlx::migrate!() + .run(&database) + .await?; println!("Bot is ready!");