diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index c7feeca..7d8f47e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,8 +9,30 @@ on: env: CARGO_TERM_COLOR: always +# Auto-abort duplicate jobs (e.g. job being triggered again on push to open PR) +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - linux: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.13" + - name: Install pre-commit + run: | + python -m pip install --upgrade pip + pip install pre-commit + - name: Run pre-commit + run: pre-commit run --all-files + + build-linux: runs-on: ubuntu-latest steps: - uses: ikalnytskyi/action-setup-postgres@v6 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d32d9e2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "crates/sonata"] + path = crates/sonata + url = https://github.com/polyphony-chat/sonata.git diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1e9561d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: +- repo: https://github.com/sqlfluff/sqlfluff + rev: 27ef5db7053dfd00c93e1c5283e38780d7f6e0c5 + hooks: + - id: sqlfluff-lint + args: [--dialect, "postgres", -e, "LT05"] + - id: sqlfluff-fix + args: [--dialect, "postgres", -e, "LT05"] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 2decb06..9b6b144 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,17 @@ { - "rust-analyzer.cargo.features": "all" + "rust-analyzer.cargo.features": "all", + "sqltools.connections": [ + { + "previewLimit": 50, + "server": "localhost", + "port": 5432, + "driver": "PostgreSQL", + "database": "symfonia", + "username": "symfonia", + "password": "symfonia", + "name": "localdb" + } + ], + "sqlfluff.dialect": "postgres", + "sqlfluff.excludeRules": ["LT05"] } diff --git a/Cargo.toml b/Cargo.toml index 2980581..f9fdcfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,5 @@ tokio-tungstenite = { version = "0.26.2", features = [ "rustls-tls-webpki-roots", "url", ] } -sqlx = "0.8.5" +sqlx = "0.8.6" sqlx-pg-uint = { version = "0.10.1", features = ["serde"] } diff --git a/README.md b/README.md index 827becd..70b041c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +> [!IMPORTANT] +> 📦️ We moved! Come check out our new place over on [Codeberg](https://codeberg.org/polyphony)! ([Repository link](https://codeberg.org/polyphony/symfonia)) +> +> We have moved to [Codeberg](https://codeberg.org/polyphony) as our primary Git Forge, and the project is *alive and well* over there! :purple_heart: The GitHub repositories will be archived and potentially deleted in the future. +
[![Discord]][Discord-invite] @@ -17,15 +22,17 @@ ## About -This is a WIP implementation of a Spacebar compatible Server in Rust! +This is a WIP implementation of a polyproto-chat compatible Server in Rust. + +> [!Warning] +> This server is still in early development and thus not yet usable. This repository contains: A partial implementation of: -- [HTTP API Server](/src/api) -- [HTTP CDN Server](/src/cdn) -- [WebSocket Gateway Server](/src/gateway) -- [Database Models](/src/database) +- [HTTP API Server](/src/crates/symfonia-api) +- [WebSocket Gateway Server](/src/crates/symfonia-gateway) +- [Database Models](/src/crates/util/migrations) ## Local Development/Test Environment @@ -35,6 +42,8 @@ Whether you are using Docker or not, you will need to have the following install - [git](https://git-scm.com/downloads) - [`sqlx-cli`](https://crates.io/crates/sqlx-cli) +You will also have to run `git submodule update` after cloning the repository. + If your development environment is hosted on a Windows machine, please additionally make sure that you have a bash shell available to execute pre-commit hooks. This can be done by installing [Git Bash](https://git-scm.com/downloads) or @@ -57,12 +66,8 @@ DATABASE_PASSWORD=[Your Postgres password] DATABASE_NAME=[Your Postgres database name] API_BIND=[ip:port to bind the HTTP API server to. Defaults to 0.0.0.0:3001 if not set] GATEWAY_BIND=[ip:port to bind the Gateway server to. Defaults to 0.0.0.0:3003 if not set] -# For rauthy: -COOKIE_MODE=danger-insecure ``` -4. Install and host an instance of [rauthy](https://github.com/sebadob/rauthy). Documentation on how - to do this can be found [here](https://sebadob.github.io/rauthy/intro.html). 5. Install the sqlx CLI with `cargo install sqlx-cli` 6. Run `cargo sqlx migrate run` from within the project directory to run the migrations 7. Run the project with `cargo run`. @@ -71,19 +76,8 @@ COOKIE_MODE=danger-insecure 1. Copy the `compose-example.env` file to `.env` in the root of the compose project and fill in the values to your liking. -2. Create a `rauthy.cfg` in the root of the compose project and fill in the - values according to [the rauthy documentation. A reference config is included on that page](https://sebadob.github.io/rauthy/config/config.html#reference-config). - - !!! tip - - rauthy also supports PostgreSQL as a database backend, but comes with [Hiqlite](https://github.com/sebadob/hiqlite) - as a default database backend.fe - -3. Adjust ports in `docker-compose.yml` if needed. -4. Run `docker compose up --build`. - -If you haven't edited the corresponding `rauthy.cfg` settings, the default user for rauthy is `admin@localhost.de`. -The password will be generated at first launch and you can discover it using `docker compose logs`. +2. Adjust ports in `docker-compose.yml` if needed. +3. Run `docker compose up --build`. Code changes will require you to restart the container with `docker compose up --build`. If you want to reset to a fully clean state, run `docker compose down -v`. diff --git a/crates/sonata b/crates/sonata new file mode 160000 index 0000000..550d0a7 --- /dev/null +++ b/crates/sonata @@ -0,0 +1 @@ +Subproject commit 550d0a70bf83af50f385088b58554c384e2b6621 diff --git a/crates/symfonia-api/Cargo.toml b/crates/symfonia-api/Cargo.toml index c107f7c..fa02023 100644 --- a/crates/symfonia-api/Cargo.toml +++ b/crates/symfonia-api/Cargo.toml @@ -8,7 +8,7 @@ edition = "2024" [dependencies] base64 = "0.22.1" bigdecimal = "0.4.8" -bitflags = { version = "2.9.0", features = ["serde"] } +bitflags = { version = "2.9.1", features = ["serde"] } chrono = { version = "0.4.41", features = ["serde"] } futures = "0.3.31" hostname = "0.4.1" @@ -23,11 +23,11 @@ log4rs = { version = "1.3.0", features = [ ] } num-bigint = "0.4.6" num-traits = "0.2.19" -openssl = "0.10.72" -poem = "3.1.9" +openssl = "0.10.73" +poem = "3.1.11" rand = "0.8.5" regex = "1.11.1" -reqwest = { version = "0.12.15", default-features = false, features = [ +reqwest = { version = "0.12.20", default-features = false, features = [ "http2", "macos-system-configuration", "charset", @@ -43,7 +43,7 @@ sqlx = { workspace = true, features = [ "any", ] } thiserror = "1.0.69" -tokio = { version = "1.44.2", features = ["full"] } +tokio = { version = "1.45.1", features = ["full"] } sentry = { version = "0.34.0", default-features = false, features = [ "backtrace", "contexts", @@ -63,9 +63,9 @@ tokio-tungstenite = { version = "0.23.1", features = [ "tokio-rustls", ] } pubserve = { version = "1.1.0", features = ["async", "send"] } -parking_lot = { version = "0.12.3", features = ["deadlock_detection"] } +parking_lot = { version = "0.12.4", features = ["deadlock_detection"] } sqlx-pg-uint = { workspace = true } -toml = "0.8.22" +toml = "0.8.23" argon2 = "0.5.3" [profile.release] diff --git a/crates/symfonia-gateway/Cargo.toml b/crates/symfonia-gateway/Cargo.toml index a179f81..5de644a 100644 --- a/crates/symfonia-gateway/Cargo.toml +++ b/crates/symfonia-gateway/Cargo.toml @@ -8,7 +8,7 @@ edition = "2024" [dependencies] base64 = "0.22.1" bigdecimal = "0.4.8" -bitflags = { version = "2.9.0", features = ["serde"] } +bitflags = { version = "2.9.1", features = ["serde"] } chrono = { version = "0.4.41", features = ["serde"] } futures = "0.3.31" jsonwebtoken = "9.3.1" @@ -22,11 +22,11 @@ log4rs = { version = "1.3.0", features = [ ] } num-bigint = "0.4.6" num-traits = "0.2.19" -openssl = "0.10.72" -poem = "3.1.9" +openssl = "0.10.73" +poem = "3.1.11" rand = "0.8.5" regex = "1.11.1" -reqwest = { version = "0.12.15", default-features = false, features = [ +reqwest = { version = "0.12.20", default-features = false, features = [ "http2", "macos-system-configuration", "charset", @@ -42,7 +42,7 @@ sqlx = { workspace = true, features = [ "any", ] } thiserror = "1.0.69" -tokio = { version = "1.44.2", features = ["full"] } +tokio = { version = "1.45.1", features = ["full"] } chorus = { workspace = true } util = { path = "../util", version = "0" } serde_path_to_error = "0.1.17" @@ -50,8 +50,8 @@ percent-encoding = "2.3.1" hex = "0.4.3" tokio-tungstenite = { workspace = true } pubserve = { version = "1.1.0", features = ["async", "send"] } -parking_lot = { version = "0.12.3", features = ["deadlock_detection"] } -toml = "0.8.22" +parking_lot = { version = "0.12.4", features = ["deadlock_detection"] } +toml = "0.8.23" argon2 = "0.5.3" [profile.release] diff --git a/crates/symfonia/Cargo.toml b/crates/symfonia/Cargo.toml index 78ae3b9..1a6e2e4 100644 --- a/crates/symfonia/Cargo.toml +++ b/crates/symfonia/Cargo.toml @@ -5,13 +5,13 @@ edition = "2024" license = "MPL-2.0" [dependencies] -clap = { version = "4.5.37", features = ["derive"] } +clap = { version = "4.5.40", features = ["derive"] } lazy_static = "1.5.0" log = "0.4.27" log4rs = "1.3.0" serde = { version = "1.0.219", features = ["derive"] } -tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] } -toml = "0.8.22" +tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] } +toml = "0.8.23" util = { version = "0.1.0", path = "../util" } sqlx = { workspace = true } symfonia-api = { version = "0.1.0", path = "../symfonia-api" } diff --git a/crates/util/Cargo.toml b/crates/util/Cargo.toml index aae0d53..9121420 100644 --- a/crates/util/Cargo.toml +++ b/crates/util/Cargo.toml @@ -21,22 +21,22 @@ jsonwebtoken = "9.3.1" log = "0.4.27" log4rs = "1.3.0" num-traits = "0.2.19" -parking_lot = "0.12.3" -poem = { version = "3.1.9", optional = true } +parking_lot = "0.12.4" +poem = { version = "3.1.11", optional = true } pubserve = "1.1.0" rand = "0.8.5" -reqwest = "0.12.15" +reqwest = "0.12.20" secrecy = "0.10.3" serde = "1.0.219" serde_json = "1.0.140" serde_path_to_error = "0.1.17" -serde_with = "3.12.0" +serde_with = "3.13.0" sqlx = { workspace = true } sqlx-pg-uint = { workspace = true } thiserror = "2.0.12" -tokio = { version = "1.44.2", features = ["net", "rt-multi-thread", "sync"] } +tokio = { version = "1.45.1", features = ["net", "rt-multi-thread", "sync"] } tokio-tungstenite = { workspace = true } -toml = "0.8.22" +toml = "0.8.23" zeroize = { version = "1.8.1", features = ["derive"] } [dev-dependencies] diff --git a/crates/util/fixtures/guilds.sql b/crates/util/fixtures/guilds.sql index 8f9b01b..41d95ea 100644 --- a/crates/util/fixtures/guilds.sql +++ b/crates/util/fixtures/guilds.sql @@ -1,18 +1,18 @@ INSERT INTO guilds ( - id, afk_channel_id, afk_timeout, banner, default_message_notifications, - description, discovery_splash, explicit_content_filter, features, - primary_category_id, icon, large, max_members, max_presences, - max_video_channel_users, member_count, presence_count, template_id, - mfa_level, name, owner_id, preferred_locale, premium_subscription_count, - premium_tier, public_updates_channel_id, rules_channel_id, region, - splash, system_channel_id, system_channel_flags, unavailable, - verification_level, welcome_screen, widget_channel_id, widget_enabled, + id, afk_channel_id, afk_timeout, banner, default_message_notifications, + description, discovery_splash, explicit_content_filter, features, + primary_category_id, icon, large, max_members, max_presences, + max_video_channel_users, member_count, presence_count, template_id, + mfa_level, name, owner_id, preferred_locale, premium_subscription_count, + premium_tier, public_updates_channel_id, rules_channel_id, region, + splash, system_channel_id, system_channel_flags, unavailable, + verification_level, welcome_screen, widget_channel_id, widget_enabled, nsfw_level, nsfw, parent, premium_progress_bar_enabled -) +) VALUES ( 7249086638293258240, NULL, 300, 'banner-image.png', 1, 'The first guild', 'splash-image.png', 2, '["COMMUNITY", "NEWS"]', - 'community', 'icon-image.png', TRUE, 5000, 500, + 'community', 'icon-image.png', TRUE, 5000, 500, 50, NULL, NULL, NULL, 1, 'A Guild', NULL, 'en-US', 0, 2, NULL, NULL, 'us-west', 'splash-image.png', NULL, 0, FALSE, @@ -21,31 +21,68 @@ VALUES ( ); INSERT INTO channels ( - id, created_at, name, icon, type, last_message_id, guild_id, parent_id, owner_id, last_pin_timestamp, - default_auto_archive_duration, "position", permission_overwrites, video_quality_mode, bitrate, user_limit, nsfw, - rate_limit_per_user, topic, retention_policy_id, flags, default_thread_rate_limit_per_user + id, + created_at, + name, + icon, + type, + last_message_id, + guild_id, + parent_id, + owner_id, + last_pin_timestamp, + default_auto_archive_duration, + position, + permission_overwrites, + video_quality_mode, + bitrate, + user_limit, + nsfw, + rate_limit_per_user, + topic, + retention_policy_id, + flags, + default_thread_rate_limit_per_user ) VALUES ( - 7249086862017433600, current_timestamp, 'general', NULL, 0, NULL, 7249086638293258240, NULL, - NULL, NULL, NULL, 0, NULL,NULL, NULL, NULL, false, 0, 'A channel in a guild. Exciting!', NULL, + 7249086862017433600, + current_timestamp, + 'general', + NULL, + 0, + NULL, + 7249086638293258240, + NULL, + NULL, + NULL, + NULL, + 0, + NULL, + NULL, + NULL, + NULL, + FALSE, + 0, + 'A channel in a guild. Exciting!', + NULL, 0, 0 ); INSERT INTO guilds ( - id, afk_channel_id, afk_timeout, banner, default_message_notifications, - description, discovery_splash, explicit_content_filter, features, - primary_category_id, icon, large, max_members, max_presences, - max_video_channel_users, member_count, presence_count, template_id, - mfa_level, name, owner_id, preferred_locale, premium_subscription_count, - premium_tier, public_updates_channel_id, rules_channel_id, region, - splash, system_channel_id, system_channel_flags, unavailable, - verification_level, welcome_screen, widget_channel_id, widget_enabled, + id, afk_channel_id, afk_timeout, banner, default_message_notifications, + description, discovery_splash, explicit_content_filter, features, + primary_category_id, icon, large, max_members, max_presences, + max_video_channel_users, member_count, presence_count, template_id, + mfa_level, name, owner_id, preferred_locale, premium_subscription_count, + premium_tier, public_updates_channel_id, rules_channel_id, region, + splash, system_channel_id, system_channel_flags, unavailable, + verification_level, welcome_screen, widget_channel_id, widget_enabled, nsfw_level, nsfw, parent, premium_progress_bar_enabled -) +) VALUES ( 7249112309484752896, NULL, 300, 'banner-image.png', 1, 'The second guild', 'splash-image.png', 2, '["COMMUNITY", "NEWS"]', - 'community', 'icon-image.png', TRUE, 5000, 500, + 'community', 'icon-image.png', TRUE, 5000, 500, 50, NULL, NULL, NULL, 1, 'Another Guild', NULL, 'de-DE', 0, 2, NULL, NULL, 'us-west', 'splash-image.png', NULL, 0, FALSE, @@ -54,12 +91,49 @@ VALUES ( ); INSERT INTO channels ( - id, created_at, name, icon, type, last_message_id, guild_id, parent_id, owner_id, last_pin_timestamp, - default_auto_archive_duration, "position", permission_overwrites, video_quality_mode, bitrate, user_limit, nsfw, - rate_limit_per_user, topic, retention_policy_id, flags, default_thread_rate_limit_per_user + id, + created_at, + name, + icon, + type, + last_message_id, + guild_id, + parent_id, + owner_id, + last_pin_timestamp, + default_auto_archive_duration, + position, + permission_overwrites, + video_quality_mode, + bitrate, + user_limit, + nsfw, + rate_limit_per_user, + topic, + retention_policy_id, + flags, + default_thread_rate_limit_per_user ) VALUES ( - 7249112493841190912, current_timestamp, 'general', NULL, 0, NULL, 7249112309484752896, NULL, - NULL, NULL, NULL, 0, NULL,NULL, NULL, NULL, false, 0, 'A channel in the second guild. Exciting!', NULL, + 7249112493841190912, + current_timestamp, + 'general', + NULL, + 0, + NULL, + 7249112309484752896, + NULL, + NULL, + NULL, + NULL, + 0, + NULL, + NULL, + NULL, + NULL, + FALSE, + 0, + 'A channel in the second guild. Exciting!', + NULL, 0, 0 -); \ No newline at end of file +); diff --git a/crates/util/fixtures/notes.sql b/crates/util/fixtures/notes.sql index ca30b51..eec6b1a 100644 --- a/crates/util/fixtures/notes.sql +++ b/crates/util/fixtures/notes.sql @@ -1,49 +1,170 @@ BEGIN; INSERT INTO user_settings ( - index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers, - contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted, - detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command, - explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play, + index, + afk_timeout, + allow_accessibility_detection, + animate_emoji, + animate_stickers, + contact_sync_enabled, + convert_emoticons, + custom_status, + default_guilds_restricted, + detect_platform_accounts, + developer_mode, + disable_games_tab, + enable_tts_command, + explicit_content_filter, + friend_source_flags, + gateway_connected, + gif_auto_play, guild_folders, guild_positions, inline_attachment_media, inline_embed_media, - locale, message_display_compact, native_phone_integration_enabled, render_embeds, + locale, + message_display_compact, + native_phone_integration_enabled, + render_embeds, render_reactions, restricted_guilds, show_current_game, status, stream_notifications_enabled, theme, timezone_offset ) VALUES - (7251169922837909504, 300, true, true, 1, true, true, 'Working on project', false, true, true, false, - true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, - 'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true, - 'dark', -7), - (7251169922837909505, 600, false, false, 0, false, false, 'Available', false, false, false, true, - false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false, - false, false, NULL, false, 'away', false, 'light', 1); +( + 7251169922837909504, + 300, + true, + true, + 1, + true, + true, + 'Working on project', + false, + true, + true, + false, + true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, + 'en-US', + false, + true, + true, + true, + 'restricted_guilds_data', + true, + 'online', + true, + 'dark', -7 +), +( + 7251169922837909505, + 600, + false, + false, + 0, + false, + false, + 'Available', + false, + false, + false, + true, + false, + 0, + null, + false, + false, + null, + null, + false, + false, + 'fr-FR', + true, + false, + false, false, null, false, 'away', false, 'light', 1 +); INSERT INTO users ( - id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns, - phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed, + id, + username, + discriminator, + avatar, + accent_color, + banner, + theme_colors, + pronouns, + phone, + desktop, + mobile, + premium, + premium_type, + bot, + bio, + system, + nsfw_allowed, mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, premium_since, verified, disabled, deleted, email, flags, public_flags, - purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings, + purchased_flags, + premium_usage_flags, + rights, + data, + fingerprints, + extended_settings, settings_index ) VALUES - (7250861145186111490, 'john_doe_notes', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL, - 'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false, - true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', - '2024-01-02 12:00:00', true, false, false, 'john_doe_notes@example.com', 100, 10, - 5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7251169922837909504 - ), - (7250861145186111491, 'jane_smith_notes', '5678', 'avatar2.png', 123456, NULL, NULL, - 'she/her', NULL, false, true, false, 0, false, '', false, - false, false, false, NULL, NULL, '2024-02-01 15:30:00', - NULL, false, false, false, 'jane_smith_notes@example.com', 50, 5, - 0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7251169922837909505 - ); +( + 7250861145186111490, + 'john_doe_notes', + '1296', + 'avatar1.png', + 16777215, + 'banner1.png', + null, + 'he/him', + '+1234567890', + true, + false, + true, + 1, + false, + 'This is my bio', + false, + true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', + '2024-01-02 12:00:00', + true, + false, + false, + 'john_doe_notes@example.com', + 100, + 10, + 5, + 1, + 100, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu","valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint1', + '{"setting": "value"}', + 7251169922837909504 +), +( + 7250861145186111491, + 'jane_smith_notes', + '5678', + 'avatar2.png', + 123456, + null, + null, + 'she/her', null, false, true, false, 0, false, '', false, + false, false, false, null, null, '2024-02-01 15:30:00', + null, false, false, false, 'jane_smith_notes@example.com', 50, 5, + 0, + 0, + 50, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint2', + '{"setting": "another_value"}', + 7251169922837909505 +); COMMIT; INSERT INTO notes ( content, author_id, target_id ) -VALUES - ('This is a note', 7250861145186111490, 7250861145186111491), - ('This is another note', 7250861145186111491, 7250861145186111490); \ No newline at end of file +VALUES +('This is a note', 7250861145186111490, 7250861145186111491), +('This is another note', 7250861145186111491, 7250861145186111490); diff --git a/crates/util/fixtures/private_channels.sql b/crates/util/fixtures/private_channels.sql index fa80737..d96e658 100644 --- a/crates/util/fixtures/private_channels.sql +++ b/crates/util/fixtures/private_channels.sql @@ -1,58 +1,198 @@ -- Create two users with two respective user_settings, one DM channel, and add both users to that DM channel. BEGIN; INSERT INTO user_settings ( - index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers, - contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted, - detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command, - explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play, + index, + afk_timeout, + allow_accessibility_detection, + animate_emoji, + animate_stickers, + contact_sync_enabled, + convert_emoticons, + custom_status, + default_guilds_restricted, + detect_platform_accounts, + developer_mode, + disable_games_tab, + enable_tts_command, + explicit_content_filter, + friend_source_flags, + gateway_connected, + gif_auto_play, guild_folders, guild_positions, inline_attachment_media, inline_embed_media, - locale, message_display_compact, native_phone_integration_enabled, render_embeds, + locale, + message_display_compact, + native_phone_integration_enabled, + render_embeds, render_reactions, restricted_guilds, show_current_game, status, stream_notifications_enabled, theme, timezone_offset ) VALUES - (7250861145186111495, 300, true, true, 1, true, true, 'Working on project', false, true, true, false, - true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, - 'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true, - 'dark', -7), - (7250861145186111496, 600, false, false, 0, false, false, 'Available', false, false, false, true, - false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false, - false, false, NULL, false, 'away', false, 'light', 1); +( + 7250861145186111495, + 300, + true, + true, + 1, + true, + true, + 'Working on project', + false, + true, + true, + false, + true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, + 'en-US', + false, + true, + true, + true, + 'restricted_guilds_data', + true, + 'online', + true, + 'dark', -7 +), +( + 7250861145186111496, + 600, + false, + false, + 0, + false, + false, + 'Available', + false, + false, + false, + true, + false, + 0, + null, + false, + false, + null, + null, + false, + false, + 'fr-FR', + true, + false, + false, false, null, false, 'away', false, 'light', 1 +); INSERT INTO users ( - id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns, - phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed, + id, + username, + discriminator, + avatar, + accent_color, + banner, + theme_colors, + pronouns, + phone, + desktop, + mobile, + premium, + premium_type, + bot, + bio, + system, + nsfw_allowed, mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, premium_since, verified, disabled, deleted, email, flags, public_flags, - purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings, + purchased_flags, + premium_usage_flags, + rights, + data, + fingerprints, + extended_settings, settings_index ) VALUES - (7250861145186111490, 'john_doe_private_channels', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL, - 'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false, - true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', - '2024-01-02 12:00:00', true, false, false, 'john_doe_private_channels@example.com', 100, 10, - 5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7250861145186111495 - ), - (7250861145186111491, 'jane_smith_private_channels', '5678', 'avatar2.png', 123456, NULL, NULL, - 'she/her', NULL, false, true, false, 0, false, '', false, - false, false, false, NULL, NULL, '2024-02-01 15:30:00', - NULL, false, false, false, 'jane_smith_private_channels@example.com', 50, 5, - 0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7250861145186111496 - ); +( + 7250861145186111490, + 'john_doe_private_channels', + '1296', + 'avatar1.png', + 16777215, + 'banner1.png', + null, + 'he/him', + '+1234567890', + true, + false, + true, + 1, + false, + 'This is my bio', + false, + true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', + '2024-01-02 12:00:00', + true, + false, + false, + 'john_doe_private_channels@example.com', + 100, + 10, + 5, + 1, + 100, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint1', + '{"setting": "value"}', + 7250861145186111495 +), +( + 7250861145186111491, + 'jane_smith_private_channels', + '5678', + 'avatar2.png', + 123456, + null, + null, + 'she/her', null, false, true, false, 0, false, '', false, + false, false, false, null, null, '2024-02-01 15:30:00', + null, false, false, false, 'jane_smith_private_channels@example.com', 50, 5, + 0, + 0, + 50, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint2', + '{"setting": "another_value"}', + 7250861145186111496 +); COMMIT; INSERT INTO channels ( - id, created_at, name, icon, type, last_message_id, guild_id, parent_id, owner_id, last_pin_timestamp, - default_auto_archive_duration, "position", permission_overwrites, video_quality_mode, bitrate, user_limit, nsfw, - rate_limit_per_user, topic, retention_policy_id, flags, default_thread_rate_limit_per_user + id, + created_at, + name, + icon, + type, + last_message_id, + guild_id, + parent_id, + owner_id, + last_pin_timestamp, + default_auto_archive_duration, + position, + permission_overwrites, + video_quality_mode, + bitrate, + user_limit, + nsfw, + rate_limit_per_user, + topic, + retention_policy_id, + flags, + default_thread_rate_limit_per_user ) VALUES ( - 7250859537236758528, current_timestamp, NULL, NULL, 1, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, false, 0, NULL, NULL, + 7250859537236758528, current_timestamp, null, null, 1, null, null, null, + null, null, null, null, null, null, null, null, false, 0, null, null, 0, 0 ); INSERT INTO recipients (id, channel_id, user_id, closed) VALUES - (7250860729446699008, 7250859537236758528, 7250861145186111490, false), - (7250861145186111494, 7250859537236758528, 7250861145186111491, false); \ No newline at end of file +(7250860729446699008, 7250859537236758528, 7250861145186111490, false), +(7250861145186111494, 7250859537236758528, 7250861145186111491, false); diff --git a/crates/util/fixtures/users.sql b/crates/util/fixtures/users.sql index 249a97e..a04baa2 100644 --- a/crates/util/fixtures/users.sql +++ b/crates/util/fixtures/users.sql @@ -1,72 +1,282 @@ -- Inserts 5 user_settings records and 5 users records into their respective tables. BEGIN; INSERT INTO user_settings ( - index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers, - contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted, - detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command, - explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play, - guild_folders, guild_positions, inline_attachment_media, inline_embed_media, - locale, message_display_compact, native_phone_integration_enabled, render_embeds, - render_reactions, restricted_guilds, show_current_game, status, + index, + afk_timeout, + allow_accessibility_detection, + animate_emoji, + animate_stickers, + contact_sync_enabled, + convert_emoticons, + custom_status, + default_guilds_restricted, + detect_platform_accounts, + developer_mode, + disable_games_tab, + enable_tts_command, + explicit_content_filter, + friend_source_flags, + gateway_connected, + gif_auto_play, + guild_folders, guild_positions, inline_attachment_media, inline_embed_media, + locale, + message_display_compact, + native_phone_integration_enabled, + render_embeds, + render_reactions, restricted_guilds, show_current_game, status, stream_notifications_enabled, theme, timezone_offset ) -VALUES - (1, 300, true, true, 1, true, true, 'Working on project', false, true, true, false, - true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, - 'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true, - 'dark', -7), - (2, 600, false, false, 0, false, false, 'Available', false, false, false, true, - false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false, - false, false, NULL, false, 'away', false, 'light', 1), - (3, 120, false, true, 1, true, true, 'Busy coding', true, true, true, false, - true, 2, 'friends_data', true, true, 'folder3_data', 'position3_data', true, true, - 'es-ES', false, true, true, true, 'restricted_guilds_data3', false, 'dnd', true, - 'dark', -5), - (4, 240, true, true, 2, false, false, 'Gaming mode', false, true, false, false, - false, 1, 'flags_data', false, true, 'folder4_data', 'position4_data', false, false, - 'de-DE', true, true, true, false, NULL, true, 'online', false, 'dark', 0), - (5, 180, false, false, 0, true, true, 'On a break', false, false, true, true, - false, 0, 'source_flags', true, false, NULL, NULL, true, true, - 'ja-JP', false, false, false, true, 'restricted_guilds5', false, 'idle', false, - 'light', 9); +VALUES +( + 1, + 300, + true, + true, + 1, + true, + true, + 'Working on project', + false, + true, + true, + false, + true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, + 'en-US', + false, + true, + true, + true, + 'restricted_guilds_data', + true, + 'online', + true, + 'dark', -7 +), +( + 2, + 600, + false, + false, + 0, + false, + false, + 'Available', + false, + false, + false, + true, + false, + 0, + null, + false, + false, + null, + null, + false, + false, + 'fr-FR', + true, + false, + false, false, null, false, 'away', false, 'light', 1 +), +( + 3, 120, false, true, 1, true, true, 'Busy coding', true, true, true, false, + true, + 2, + 'friends_data', + true, + true, + 'folder3_data', + 'position3_data', + true, + true, + 'es-ES', + false, + true, + true, + true, + 'restricted_guilds_data3', + false, + 'dnd', + true, + 'dark', -5 +), +( + 4, + 240, + true, + true, + 2, + false, + false, + 'Gaming mode', + false, + true, + false, + false, + false, + 1, + 'flags_data', + false, + true, + 'folder4_data', + 'position4_data', + false, + false, + 'de-DE', true, true, true, false, null, true, 'online', false, 'dark', 0 +), +( + 5, 180, false, false, 0, true, true, 'On a break', false, false, true, true, + false, 0, 'source_flags', true, false, null, null, true, true, + 'ja-JP', + false, + false, + false, + true, + 'restricted_guilds5', + false, + 'idle', + false, + 'light', 9 +); INSERT INTO users ( - id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns, - phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed, - mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, - premium_since, verified, disabled, deleted, email, flags, public_flags, - purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings, + id, + username, + discriminator, + avatar, + accent_color, + banner, + theme_colors, + pronouns, + phone, + desktop, + mobile, + premium, + premium_type, + bot, + bio, + system, + nsfw_allowed, + mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, + premium_since, verified, disabled, deleted, email, flags, public_flags, + purchased_flags, + premium_usage_flags, + rights, + data, + fingerprints, + extended_settings, settings_index ) -VALUES - (7248639845155737600, 'john_doe', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL, - 'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false, - true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', - '2024-01-02 12:00:00', true, false, false, 'john_doe@example.com', 100, 10, - 5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 1 - ), - (7248639891561517057, 'jane_smith', '5678', 'avatar2.png', 123456, NULL, NULL, - 'she/her', NULL, false, true, false, 0, false, '', false, - false, false, false, NULL, NULL, '2024-02-01 15:30:00', - NULL, false, false, false, 'jane_smith@example.com', 50, 5, - 0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 2 - ), - (7248640296244744192, 'alice_malice', '9876', 'avatar3.png', 987654, 'banner3.png', NULL, - 'they/them', '+1230987654', true, true, false, 0, false, 'Life is an adventure', - false, false, true, false, 'secret789', 'ticket123', '2024-03-01 08:45:00', - NULL, false, false, false, 'alice@example.com', 200, 20, - 2, 1, 150, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint3', '{"setting3": "value3"}', 3 - ), - (7248640311927246848, 'bob_the_woz', '1122', 'avatar4.png', 556677, NULL, NULL, - 'he/him', NULL, true, false, true, 1, false, 'Building the future', - false, true, false, true, 'secret456', 'ticket789', '2024-03-15 14:30:00', - '2024-04-01 14:30:00', true, false, false, 'bob@example.com', 250, 25, - 3, 2, 200, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint4', '{"setting4": "value4"}', 4 - ), - (7248640327265816576, 'xenia', '3344', 'avatar5.png', NULL, 'banner5.png', NULL, - 'he/him', '+4567890123', false, true, false, 0, false, 'Chocolate is life', - false, false, false, true, 'secret555', 'ticket987', '2024-04-10 10:00:00', - NULL, false, false, false, 'charlie@example.com', 180, 15, - 0, 0, 180, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint5', '{"setting5": "value5"}', 5 - ); -COMMIT; \ No newline at end of file +VALUES +( + 7248639845155737600, + 'john_doe', + '1296', + 'avatar1.png', + 16777215, + 'banner1.png', + null, + 'he/him', + '+1234567890', + true, + false, + true, + 1, + false, + 'This is my bio', + false, + true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', + '2024-01-02 12:00:00', true, false, false, 'john_doe@example.com', 100, 10, + 5, + 1, + 100, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint1', + '{"setting": "value"}', + 1 +), +( + 7248639891561517057, + 'jane_smith', + '5678', + 'avatar2.png', + 123456, + null, + null, + 'she/her', null, false, true, false, 0, false, '', false, + false, false, false, null, null, '2024-02-01 15:30:00', + null, false, false, false, 'jane_smith@example.com', 50, 5, + 0, + 0, + 50, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint2', + '{"setting": "another_value"}', + 2 +), +( + 7248640296244744192, + 'alice_malice', + '9876', + 'avatar3.png', + 987654, + 'banner3.png', + null, + 'they/them', + '+1230987654', + true, + true, + false, + 0, + false, + 'Life is an adventure', + false, false, true, false, 'secret789', 'ticket123', '2024-03-01 08:45:00', + null, false, false, false, 'alice@example.com', 200, 20, + 2, + 1, + 150, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint3', + '{"setting3": "value3"}', + 3 +), +( + 7248640311927246848, + 'bob_the_woz', + '1122', + 'avatar4.png', + 556677, + null, + null, + 'he/him', null, true, false, true, 1, false, 'Building the future', + false, true, false, true, 'secret456', 'ticket789', '2024-03-15 14:30:00', + '2024-04-01 14:30:00', true, false, false, 'bob@example.com', 250, 25, + 3, + 2, + 200, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint4', + '{"setting4": "value4"}', + 4 +), +( + 7248640327265816576, + 'xenia', + '3344', + 'avatar5.png', + null, + 'banner5.png', + null, + 'he/him', '+4567890123', false, true, false, 0, false, 'Chocolate is life', + false, false, false, true, 'secret555', 'ticket987', '2024-04-10 10:00:00', + null, false, false, false, 'charlie@example.com', 180, 15, + 0, + 0, + 180, + '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', + 'fingerprint5', + '{"setting5": "value5"}', + 5 +); +COMMIT; diff --git a/crates/util/migrations.old/20231007011602_categories.sql b/crates/util/migrations.old/20231007011602_categories.sql new file mode 100644 index 0000000..8435e5e --- /dev/null +++ b/crates/util/migrations.old/20231007011602_categories.sql @@ -0,0 +1,9 @@ +create table if not exists categories +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + name varchar(255) null, + localizations text not null, + is_primary boolean null +); diff --git a/crates/util/migrations.old/20231007011617_client_release.sql b/crates/util/migrations.old/20231007011617_client_release.sql new file mode 100644 index 0000000..d07b09f --- /dev/null +++ b/crates/util/migrations.old/20231007011617_client_release.sql @@ -0,0 +1,12 @@ +create table if not exists client_release +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + name varchar(255) not null, + pub_date timestamp not null, + url varchar(255) not null, + platform varchar(255) not null, + enabled boolean not null, + notes varchar(255) null +); diff --git a/crates/util/migrations/20231007011631_config.sql b/crates/util/migrations.old/20231007011631_config.sql similarity index 56% rename from crates/util/migrations/20231007011631_config.sql rename to crates/util/migrations.old/20231007011631_config.sql index ee97f1f..8a0d5d5 100644 --- a/crates/util/migrations/20231007011631_config.sql +++ b/crates/util/migrations.old/20231007011631_config.sql @@ -1,6 +1,6 @@ create table if not exists config ( key varchar(255) not null - primary key, - value json null -); \ No newline at end of file + primary key, + value json null +); diff --git a/crates/util/migrations/20231007011653_connection_config.sql b/crates/util/migrations.old/20231007011653_connection_config.sql similarity index 60% rename from crates/util/migrations/20231007011653_connection_config.sql rename to crates/util/migrations.old/20231007011653_connection_config.sql index e62e832..623a09f 100644 --- a/crates/util/migrations/20231007011653_connection_config.sql +++ b/crates/util/migrations.old/20231007011653_connection_config.sql @@ -1,6 +1,6 @@ create table if not exists connection_config ( key varchar(255) not null - primary key, - value text null -); \ No newline at end of file + primary key, + value text null +); diff --git a/crates/util/migrations.old/20231007011705_embed_cache.sql b/crates/util/migrations.old/20231007011705_embed_cache.sql new file mode 100644 index 0000000..6bd093c --- /dev/null +++ b/crates/util/migrations.old/20231007011705_embed_cache.sql @@ -0,0 +1,8 @@ +create table if not exists embed_cache +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + url varchar(255) not null, + embed text not null +); diff --git a/crates/util/migrations.old/20231007011719_rate_limits.sql b/crates/util/migrations.old/20231007011719_rate_limits.sql new file mode 100644 index 0000000..7c7a160 --- /dev/null +++ b/crates/util/migrations.old/20231007011719_rate_limits.sql @@ -0,0 +1,14 @@ +create table if not exists rate_limits +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + executor_id numeric( + 20, 0 + ) not null constraint chk_executor_id_range check ( + executor_id >= 0 and executor_id <= 18446744073709551615 + ), + hits int not null, + blocked boolean not null, + expires_at timestamp not null +); diff --git a/crates/util/migrations.old/20231007011737_security_settings.sql b/crates/util/migrations.old/20231007011737_security_settings.sql new file mode 100644 index 0000000..5a2f84a --- /dev/null +++ b/crates/util/migrations.old/20231007011737_security_settings.sql @@ -0,0 +1,16 @@ +create table if not exists security_settings +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + encryption_permission_mask int not null, + allowed_algorithms text not null, + current_algorithm varchar(255) not null, + used_since_message varchar(255) null +); diff --git a/crates/util/migrations.old/20231007011751_sticker_packs.sql b/crates/util/migrations.old/20231007011751_sticker_packs.sql new file mode 100644 index 0000000..26c5e3f --- /dev/null +++ b/crates/util/migrations.old/20231007011751_sticker_packs.sql @@ -0,0 +1,23 @@ +create table if not exists sticker_packs +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + name varchar(255) not null, + description varchar(255) null, + banner_asset_id numeric( + 20, 0 + ) null constraint chk_banner_asset_id_range check ( + banner_asset_id >= 0 and banner_asset_id <= 18446744073709551615 + ), + cover_sticker_id numeric( + 20, 0 + ) null constraint chk_cover_sticker_id_range check ( + cover_sticker_id >= 0 and cover_sticker_id <= 18446744073709551615 + ), + coverstickerid numeric( + 20, 0 + ) null constraint chk_coverstickerid_range check ( + coverstickerid >= 0 and coverstickerid <= 18446744073709551615 + ) +); diff --git a/crates/util/migrations.old/20231007011756_user_settings.sql b/crates/util/migrations.old/20231007011756_user_settings.sql new file mode 100644 index 0000000..60e8885 --- /dev/null +++ b/crates/util/migrations.old/20231007011756_user_settings.sql @@ -0,0 +1,41 @@ +CREATE SEQUENCE user_settings_index_seq; + +CREATE TABLE IF NOT EXISTS user_settings +( + index numeric(20, 0) NOT NULL DEFAULT nextval( + 'user_settings_index_seq' + ) CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) PRIMARY KEY, + afk_timeout int NULL, + allow_accessibility_detection boolean NULL, + animate_emoji boolean NULL, + animate_stickers int NULL, + contact_sync_enabled boolean NULL, + convert_emoticons boolean NULL, + custom_status text NULL, + default_guilds_restricted boolean NULL, + detect_platform_accounts boolean NULL, + developer_mode boolean NULL, + disable_games_tab boolean NULL, + enable_tts_command boolean NULL, + explicit_content_filter int NULL, + friend_source_flags text NULL, + gateway_connected boolean NULL, + gif_auto_play boolean NULL, + guild_folders text NULL, + guild_positions text NULL, + inline_attachment_media boolean NULL, + inline_embed_media boolean NULL, + locale varchar(255) NULL, + message_display_compact boolean NULL, + native_phone_integration_enabled boolean NULL, + render_embeds boolean NULL, + render_reactions boolean NULL, + restricted_guilds text NULL, + show_current_game boolean NULL, + status varchar(255) NULL, + stream_notifications_enabled boolean NULL, + theme varchar(255) NULL, + timezone_offset int NULL +); diff --git a/crates/util/migrations.old/20231007011757_users.sql b/crates/util/migrations.old/20231007011757_users.sql new file mode 100644 index 0000000..2ab9bcd --- /dev/null +++ b/crates/util/migrations.old/20231007011757_users.sql @@ -0,0 +1,63 @@ +create table if not exists users ( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + username varchar(255) not null, + discriminator varchar(255) not null, + avatar varchar(255) null, + accent_color numeric(10, 0) null constraint chk_accent_color check ( + accent_color >= 0 and accent_color <= 4294967295 + ), + banner varchar(255) null, + theme_colors numeric(3, 0) [8] null, + pronouns varchar(255) null, + phone varchar(255) null, + desktop boolean not null default false, + mobile boolean not null default false, + premium boolean not null, + premium_type numeric( + 5, 0 + ) not null constraint chk_smallint_unsigned check ( + premium_type >= 0 and premium_type <= 65535 + ), + bot boolean not null default false, + bio varchar(255) not null default '', + system boolean not null default false, + nsfw_allowed boolean not null default false, + mfa_enabled boolean not null default false, + webauthn_enabled boolean not null default false, + totp_secret varchar(255) null, + totp_last_ticket varchar(255) null, + created_at timestamp not null, + premium_since timestamptz null, + verified boolean not null default false, + disabled boolean not null default false, + deleted boolean not null default false, + email varchar(255) null, + flags numeric(20, 0) not null constraint chk_flags_range check ( + flags >= 0 and flags <= 18446744073709551615 + ), + public_flags numeric(10, 0) not null constraint chk_int_unsigned check ( + public_flags >= 0 and public_flags <= 4294967295 + ), + purchased_flags int not null, + premium_usage_flags int not null, + rights numeric(20, 0) not null constraint chk_rights_range check ( + rights >= 0 and rights <= 18446744073709551615 + ), + data json not null, + fingerprints text not null, + extended_settings json not null, + settings_index numeric( + 20, 0 + ) null constraint chk_settings_index_range check ( + settings_index >= 0 and settings_index <= 18446744073709551615 + ), + constraint users_settings_index_uindex unique (settings_index), + constraint users_user_settings_index_fk foreign key ( + settings_index + ) references user_settings (index), + constraint check_theme_colors_elements check ( + array_length(theme_colors, 1) <= 8 + ) +); diff --git a/crates/util/migrations.old/20231007011857_audit_logs.sql b/crates/util/migrations.old/20231007011857_audit_logs.sql new file mode 100644 index 0000000..6ba3f72 --- /dev/null +++ b/crates/util/migrations.old/20231007011857_audit_logs.sql @@ -0,0 +1,23 @@ +create table if not exists audit_logs +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + guild_id numeric(20, 0) not null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + action_type int not null, + options text null, + changes text not null, + reason varchar(255) null, + target_id numeric(20, 0) null constraint chk_target_id_range check ( + target_id >= 0 and target_id <= 18446744073709551615 + ), + constraint fk_3cd01cd3ae7aab010310d96ac8e + foreign key (target_id) references users (id), + constraint fk_bd2726fd31b35443f2245b93ba0 + foreign key (user_id) references users (id) +); diff --git a/crates/util/migrations.old/20231007011910_backup_codes.sql b/crates/util/migrations.old/20231007011910_backup_codes.sql new file mode 100644 index 0000000..0800a6d --- /dev/null +++ b/crates/util/migrations.old/20231007011910_backup_codes.sql @@ -0,0 +1,15 @@ +create table if not exists backup_codes +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + code varchar(255) not null, + consumed boolean not null, + expired boolean not null, + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + constraint fk_70066ea80d2f4b871beda32633b + foreign key (user_id) references users (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007011933_channels.sql b/crates/util/migrations.old/20231007011933_channels.sql new file mode 100644 index 0000000..e6eea20 --- /dev/null +++ b/crates/util/migrations.old/20231007011933_channels.sql @@ -0,0 +1,72 @@ +create table if not exists channels +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + created_at timestamptz not null, + name varchar(255) null, + icon text null, + type int not null, + last_message_id numeric( + 20, 0 + ) null constraint chk_last_message_id_range check ( + last_message_id >= 0 and last_message_id <= 18446744073709551615 + ), + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + parent_id numeric(20, 0) null constraint chk_parent_id check ( + parent_id >= 0 and parent_id <= 18446744073709551615 + ), + owner_id numeric(20, 0) null constraint chk_owner_id_range check ( + owner_id >= 0 and owner_id <= 18446744073709551615 + ), + last_pin_timestamp int null, + default_auto_archive_duration int null, + position int null, + managed boolean null, + rtc_region varchar(255) null, + permission_overwrites text null, + video_quality_mode int null, + bitrate int null, + user_limit int null, + nsfw boolean not null, + rate_limit_per_user int null, + topic varchar(255) null, + retention_policy_id varchar(255) null, + flags int not null, + default_thread_rate_limit_per_user int not null, + default_sort_order numeric( + 3, 0 + ) null constraint chk_default_sort_order check ( + default_sort_order >= 0 and default_sort_order <= 255 + ), + -- v foreign key constraint is added in emojis migration + -- TODO: I am unsure if deserializing a channel object from the database will work with the default_reaction_emoji field. Test it + default_reaction_emoji numeric( + 20, 0 + ) null constraint chk_default_reaction_emoji check ( + default_reaction_emoji >= 0 + and default_reaction_emoji <= 18446744073709551615 + ), + default_forum_layout numeric( + 3, 0 + ) null constraint chk_default_forum_layout check ( + default_forum_layout >= 0 and default_forum_layout <= 255 + ), + available_tags jsonb null constraint chk_available_tags check ( + jsonb_typeof(available_tags) = 'array' + ) default '[]', + applied_tags jsonb null constraint chk_applied_tags check ( + jsonb_typeof(applied_tags) = 'array' + ) default '[]', + application_id numeric( + 20, 0 + ) null constraint chk_application_id_range check ( + application_id >= 0 and application_id <= 18446744073709551615 + ), + constraint fk_3274522d14af40540b1a883fc80 + foreign key (parent_id) references channels (id), + constraint fk_3873ed438575cce703ecff4fc7b + foreign key (owner_id) references users (id) +); diff --git a/crates/util/migrations.old/20231007011946_connected_accounts.sql b/crates/util/migrations.old/20231007011946_connected_accounts.sql new file mode 100644 index 0000000..e7a8e2f --- /dev/null +++ b/crates/util/migrations.old/20231007011946_connected_accounts.sql @@ -0,0 +1,24 @@ +create table if not exists connected_accounts +( + id varchar(255) not null + primary key, + external_id varchar(255) not null, + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + friend_sync boolean not null, + name varchar(255) not null, + revoked boolean not null, + show_activity int not null, + type varchar(255) not null, + verified boolean not null, + visibility int not null, + integrations text not null, + metadata text null, + metadata_visibility int not null, + two_way_link boolean not null, + token_data text null, + constraint fk_f47244225a6a1eac04a3463dd90 + foreign key (user_id) references users (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007011956_guilds.sql b/crates/util/migrations.old/20231007011956_guilds.sql new file mode 100644 index 0000000..5ce4c48 --- /dev/null +++ b/crates/util/migrations.old/20231007011956_guilds.sql @@ -0,0 +1,81 @@ +create table if not exists guilds +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + afk_channel_id numeric(20, 0) null constraint chk_afk_channel_range check ( + afk_channel_id >= 0 and afk_channel_id <= 18446744073709551615 + ), + afk_timeout int null, + banner varchar(255) null, + default_message_notifications int null, + description varchar(255) null, + discovery_splash varchar(255) null, + explicit_content_filter int null, + features jsonb not null, + primary_category_id varchar(255) null, + icon varchar(255) null, + large boolean not null, + max_members int null, + max_presences int null, + max_video_channel_users int null, + member_count int null, + presence_count int null, + template_id numeric(20, 0) null constraint chk_template_range check ( + template_id >= 0 and template_id <= 18446744073709551615 + ), + mfa_level int null, + name varchar(255) not null, + owner_id numeric(20, 0) null constraint chk_owner_id_range check ( + owner_id >= 0 and owner_id <= 18446744073709551615 + ), + preferred_locale varchar(255) null, + premium_subscription_count int null, + premium_tier int not null, + public_updates_channel_id numeric( + 20, 0 + ) null constraint check_pub_upd_channel_id check ( + public_updates_channel_id >= 0 + and public_updates_channel_id <= 18446744073709551615 + ), + rules_channel_id numeric( + 20, 0 + ) null constraint chk_rules_channel_id check ( + rules_channel_id >= 0 and rules_channel_id <= 18446744073709551615 + ), + region varchar(255) null, + splash varchar(255) null, + system_channel_id numeric( + 20, 0 + ) null constraint chk_system_channel_id check ( + system_channel_id >= 0 and system_channel_id <= 18446744073709551615 + ), + system_channel_flags int null, + unavailable boolean not null, + verification_level int null, + welcome_screen jsonb not null, + widget_channel_id numeric( + 20, 0 + ) null constraint chk_widget_channel_id check ( + widget_channel_id >= 0 and widget_channel_id <= 18446744073709551615 + ), + widget_enabled boolean not null, + nsfw_level int null, + nsfw boolean not null, + parent numeric(20, 0) null constraint chk_parent_id check ( + parent >= 0 and parent <= 18446744073709551615 + ), + premium_progress_bar_enabled boolean null, + constraint fk_public_updates_channel_id + foreign key (public_updates_channel_id) references channels (id), + constraint fk_rules_channel_id + foreign key (rules_channel_id) references channels (id), + constraint fk_widget_channel_id + foreign key (widget_channel_id) references channels (id), + constraint fk_system_channel_id + foreign key (system_channel_id) references channels (id), + constraint fk_afk_channel_id + foreign key (afk_channel_id) references channels (id), + constraint fk_owner_user_id + foreign key (owner_id) references users (id) +); diff --git a/crates/util/migrations.old/20231007012027_bans.sql b/crates/util/migrations.old/20231007012027_bans.sql new file mode 100644 index 0000000..34be1da --- /dev/null +++ b/crates/util/migrations.old/20231007012027_bans.sql @@ -0,0 +1,25 @@ +create table if not exists bans +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + executor_id numeric(20, 0) null constraint chk_executor_id check ( + executor_id >= 0 and executor_id <= 18446744073709551615 + ), + ip varchar(255) not null, + reason varchar(255) null, + constraint fk_07ad88c86d1f290d46748410d58 + foreign key (executor_id) references users (id), + constraint fk_5999e8e449f80a236ff72023559 + foreign key (user_id) references users (id) + on delete cascade, + constraint fk_9d3ab7dd180ebdd245cdb66ecad + foreign key (guild_id) references guilds (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012049_channels_guild_id_fk.sql b/crates/util/migrations.old/20231007012049_channels_guild_id_fk.sql new file mode 100644 index 0000000..adbc978 --- /dev/null +++ b/crates/util/migrations.old/20231007012049_channels_guild_id_fk.sql @@ -0,0 +1,4 @@ +alter table channels +add constraint fk_c253dafe5f3a03ec00cd8fb4581 +foreign key (guild_id) references guilds (id) +on delete cascade; diff --git a/crates/util/migrations.old/20231007012108_emojis.sql b/crates/util/migrations.old/20231007012108_emojis.sql new file mode 100644 index 0000000..d276bc6 --- /dev/null +++ b/crates/util/migrations.old/20231007012108_emojis.sql @@ -0,0 +1,29 @@ +create table if not exists emojis +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + animated boolean not null, + available boolean not null, + guild_id numeric(20, 0) not null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + managed boolean not null, + name varchar(255) not null, + require_colons boolean not null, + roles text not null, + groups text null, + constraint fk_4b988e0db89d94cebcf07f598cc + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_fa7ddd5f9a214e28ce596548421 + foreign key (user_id) references users (id) +); + +alter table channels +add constraint fk_emoji_id_emojis_id foreign key ( + default_reaction_emoji +) references emojis (id); diff --git a/crates/util/migrations.old/20231007012121_invites.sql b/crates/util/migrations.old/20231007012121_invites.sql new file mode 100644 index 0000000..7a42d44 --- /dev/null +++ b/crates/util/migrations.old/20231007012121_invites.sql @@ -0,0 +1,38 @@ +create table if not exists invites +( + code varchar(255) not null primary key, + type boolean not null, + temporary boolean not null, + uses int not null, + max_uses int not null, + max_age int not null, + created_at timestamp not null, + expires_at timestamp null, + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + inviter_id numeric(20, 0) null constraint chk_inviter_id check ( + inviter_id >= 0 and inviter_id <= 18446744073709551615 + ), + target_user_id numeric(20, 0) null constraint chk_target_user_id check ( + target_user_id >= 0 and target_user_id <= 18446744073709551615 + ), + target_user_type int null, + vanity_url boolean null, + flags int not null, + constraint fk_11a0d394f8fc649c19ce5f16b59 + foreign key (target_user_id) references users (id) + on delete cascade, + constraint fk_15c35422032e0b22b4ada95f48f + foreign key (inviter_id) references users (id) + on delete cascade, + constraint fk_3f4939aa1461e8af57fea3fb05d + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_6a15b051fe5050aa00a4b9ff0f6 + foreign key (channel_id) references channels (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012133_members.sql b/crates/util/migrations.old/20231007012133_members.sql new file mode 100644 index 0000000..bb03ce2 --- /dev/null +++ b/crates/util/migrations.old/20231007012133_members.sql @@ -0,0 +1,45 @@ +CREATE SEQUENCE members_index_seq; + +CREATE TABLE IF NOT EXISTS members +( + index numeric(20, 0) NOT NULL DEFAULT nextval( + 'members_index_seq' + ) CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) PRIMARY KEY, + id numeric(20, 0) NOT NULL CONSTRAINT chk_id_range CHECK ( + id >= 0 AND id <= 18446744073709551615 + ), + guild_id numeric(20, 0) NOT NULL CONSTRAINT chk_guild_id_range CHECK ( + guild_id >= 0 AND guild_id <= 18446744073709551615 + ), + nick varchar(255) NULL, + joined_at timestamp NOT NULL, + premium_since bigint NULL, + deaf boolean NOT NULL, + mute boolean NOT NULL, + pending boolean NOT NULL, + settings text NOT NULL, + last_message_id numeric( + 20, 0 + ) NULL CONSTRAINT chk_last_message_id_range CHECK ( + last_message_id >= 0 AND last_message_id <= 18446744073709551615 + ), + joined_by varchar(255) NULL, + avatar varchar(255) NULL, + banner varchar(255) NULL, + bio varchar(255) NOT NULL, + theme_colors text NULL, + pronouns varchar(255) NULL, + communication_disabled_until timestamp NULL, + CONSTRAINT idx_bb2bf9386ac443afbbbf9f12d3 + UNIQUE (id, guild_id), + CONSTRAINT fk_16aceddd5b89825b8ed6029ad1c + FOREIGN KEY (guild_id) REFERENCES guilds (id) + ON DELETE CASCADE, + CONSTRAINT fk_28b53062261b996d9c99fa12404 + FOREIGN KEY (id) REFERENCES users (id) + ON DELETE CASCADE +); + +ALTER SEQUENCE members_index_seq OWNED BY members.index; diff --git a/crates/util/migrations.old/20231007012149_notes.sql b/crates/util/migrations.old/20231007012149_notes.sql new file mode 100644 index 0000000..fcf2259 --- /dev/null +++ b/crates/util/migrations.old/20231007012149_notes.sql @@ -0,0 +1,25 @@ +CREATE SEQUENCE notes_index_seq; + +CREATE TABLE IF NOT EXISTS notes +( + index numeric(20, 0) NOT NULL DEFAULT nextval( + 'notes_index_seq' + ) CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) PRIMARY KEY, + content varchar(256) NOT NULL, + author_id numeric(20, 0) NULL CONSTRAINT chk_author_id_range CHECK ( + author_id >= 0 AND author_id <= 18446744073709551615 + ), + target_id numeric(20, 0) NULL CONSTRAINT chk_target_id_range CHECK ( + target_id >= 0 AND target_id <= 18446744073709551615 + ), + CONSTRAINT idx_74e6689b9568cc965b8bfc9150 + UNIQUE (author_id, target_id), + CONSTRAINT fk_23e08e5b4481711d573e1abecdc + FOREIGN KEY (target_id) REFERENCES users (id) + ON DELETE CASCADE, + CONSTRAINT fk_f9e103f8ae67cb1787063597925 + FOREIGN KEY (author_id) REFERENCES users (id) + ON DELETE CASCADE +); diff --git a/crates/util/migrations.old/20231007012204_read_states.sql b/crates/util/migrations.old/20231007012204_read_states.sql new file mode 100644 index 0000000..08d2a68 --- /dev/null +++ b/crates/util/migrations.old/20231007012204_read_states.sql @@ -0,0 +1,31 @@ +create table if not exists read_states +( + channel_id numeric(20, 0) not null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + user_id numeric(20, 0) not null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + last_message_id numeric( + 20, 0 + ) null constraint chk_last_message_id_range check ( + last_message_id >= 0 and last_message_id <= 18446744073709551615 + ), + public_ack varchar(255) null, + notifications_cursor numeric( + 20, 0 + ) null constraint chk_notifications_cursor_range check ( + notifications_cursor >= 0 + and notifications_cursor <= 18446744073709551615 + ), + last_pin_timestamp timestamp null, + mention_count int null, + constraint read_states_channel_id_user_id_uindex + unique (channel_id, user_id), + constraint read_states_users_id_fk + foreign key (user_id) references users (id) + on delete cascade, + constraint read_states_channels_id_fk + foreign key (channel_id) references channels (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012219_recipients.sql b/crates/util/migrations.old/20231007012219_recipients.sql new file mode 100644 index 0000000..f4ef583 --- /dev/null +++ b/crates/util/migrations.old/20231007012219_recipients.sql @@ -0,0 +1,19 @@ +create table if not exists recipients +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + channel_id numeric(20, 0) not null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + user_id numeric(20, 0) not null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + closed boolean default false not null, + constraint fk_2f18ee1ba667f233ae86c0ea60e + foreign key (channel_id) references channels (id) + on delete cascade, + constraint fk_6157e8b6ba4e6e3089616481fe2 + foreign key (user_id) references users (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012235_relationships.sql b/crates/util/migrations.old/20231007012235_relationships.sql new file mode 100644 index 0000000..77bf85a --- /dev/null +++ b/crates/util/migrations.old/20231007012235_relationships.sql @@ -0,0 +1,29 @@ +CREATE SEQUENCE relationships_index_seq; + +CREATE TABLE IF NOT EXISTS relationships +( + index numeric(20, 0) NOT NULL DEFAULT nextval( + 'relationships_index_seq' + ) CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) PRIMARY KEY, + from_id numeric(20, 0) NOT NULL CONSTRAINT chk_from_id_range CHECK ( + from_id >= 0 AND from_id <= 18446744073709551615 + ), + to_id numeric(20, 0) NOT NULL CONSTRAINT chk_to_id_range CHECK ( + to_id >= 0 AND to_id <= 18446744073709551615 + ), + nickname varchar(255) NULL, + type numeric(3, 0) NOT NULL CONSTRAINT chk_type_range CHECK ( + type >= 0 AND type <= 255 + ), + since timestamptz NULL DEFAULT now(), + CONSTRAINT fk_unique_relationships + UNIQUE (from_id, to_id), + CONSTRAINT fk_from_id_references_users_id + FOREIGN KEY (from_id) REFERENCES users (id) + ON DELETE CASCADE, + CONSTRAINT fk_to_id_references_users_id + FOREIGN KEY (to_id) REFERENCES users (id) + ON DELETE CASCADE +); diff --git a/crates/util/migrations.old/20231007012255_roles.sql b/crates/util/migrations.old/20231007012255_roles.sql new file mode 100644 index 0000000..75568a4 --- /dev/null +++ b/crates/util/migrations.old/20231007012255_roles.sql @@ -0,0 +1,23 @@ +create table if not exists roles +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + guild_id numeric(20, 0) not null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + color int not null, + hoist boolean not null, + managed boolean not null, + mentionable boolean not null, + name varchar(255) not null, + permissions varchar(255) not null, + position int not null, + icon varchar(255) null, + unicode_emoji varchar(255) null, + tags text null, + flags int default 0 not null, + constraint fk_c32c1ab1c4dc7dcb0278c4b1b8b + foreign key (guild_id) references guilds (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012306_member_roles.sql b/crates/util/migrations.old/20231007012306_member_roles.sql new file mode 100644 index 0000000..888965e --- /dev/null +++ b/crates/util/migrations.old/20231007012306_member_roles.sql @@ -0,0 +1,23 @@ +CREATE SEQUENCE member_roles_index_seq; + +CREATE TABLE IF NOT EXISTS member_roles +( + index numeric(20, 0) NOT NULL CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) UNIQUE, + role_id numeric(20, 0) NOT NULL CONSTRAINT chk_role_id_range CHECK ( + role_id >= 0 AND role_id <= 18446744073709551615 + ), + PRIMARY KEY (index, role_id), + CONSTRAINT fk_5d7ddc8a5f9c167f548625e772e + FOREIGN KEY (index) REFERENCES members (index) + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT fk_e9080e7a7997a0170026d5139c1 + FOREIGN KEY (role_id) REFERENCES roles (id) + ON UPDATE CASCADE ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS idx_e9080e7a7997a0170026d5139c +ON member_roles (role_id); + +ALTER SEQUENCE member_roles_index_seq OWNED BY member_roles.index; diff --git a/crates/util/migrations.old/20231007012332_security_keys.sql b/crates/util/migrations.old/20231007012332_security_keys.sql new file mode 100644 index 0000000..8cb3b1e --- /dev/null +++ b/crates/util/migrations.old/20231007012332_security_keys.sql @@ -0,0 +1,18 @@ +create table if not exists security_keys +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + key_id numeric(20, 0) not null constraint chk_key_id_range check ( + key_id >= 0 and key_id <= 18446744073709551615 + ), + public_key varchar(255) not null, + counter int not null, + name varchar(255) not null, + constraint fk_24c97d0771cafedce6d7163eaad + foreign key (user_id) references users (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012343_sessions.sql b/crates/util/migrations.old/20231007012343_sessions.sql new file mode 100644 index 0000000..ef84bea --- /dev/null +++ b/crates/util/migrations.old/20231007012343_sessions.sql @@ -0,0 +1,22 @@ +CREATE SEQUENCE sessions_index_seq; + +CREATE TABLE IF NOT EXISTS sessions +( + index numeric(20, 0) NOT NULL DEFAULT nextval( + 'user_settings_index_seq' + ) CONSTRAINT chk_index_range CHECK ( + index >= 0 AND index <= 18446744073709551615 + ) PRIMARY KEY, + user_id numeric(20, 0) NULL CONSTRAINT chk_user_id_range CHECK ( + user_id >= 0 AND user_id <= 18446744073709551615 + ), + session_id numeric(20, 0) NOT NULL CONSTRAINT chk_session_id_range CHECK ( + session_id >= 0 AND session_id <= 18446744073709551615 + ), + activities text NULL, + client_info text NOT NULL, + status varchar(255) NOT NULL, + CONSTRAINT fk_085d540d9f418cfbdc7bd55bb19 + FOREIGN KEY (user_id) REFERENCES users (id) + ON DELETE CASCADE +); diff --git a/crates/util/migrations.old/20231007012359_stickers.sql b/crates/util/migrations.old/20231007012359_stickers.sql new file mode 100644 index 0000000..d9357c6 --- /dev/null +++ b/crates/util/migrations.old/20231007012359_stickers.sql @@ -0,0 +1,34 @@ +create table if not exists stickers +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + name varchar(255) not null, + description varchar(255) null, + available boolean null, + tags varchar(255) null, + pack_id numeric(20, 0) null constraint chk_pack_id_range check ( + pack_id >= 0 and pack_id <= 18446744073709551615 + ), + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + type int not null, + format_type int not null, + constraint fk_193d551d852aca5347ef5c9f205 + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_8f4ee73f2bb2325ff980502e158 + foreign key (user_id) references users (id) + on delete cascade, + constraint fk_e7cfa5cefa6661b3fb8fda8ce69 + foreign key (pack_id) references sticker_packs (id) + on delete cascade +); + +alter table sticker_packs +add constraint fk_448fafba4355ee1c837bbc865f1 +foreign key (coverstickerid) references stickers (id); diff --git a/crates/util/migrations.old/20231007012439_teams.sql b/crates/util/migrations.old/20231007012439_teams.sql new file mode 100644 index 0000000..198e752 --- /dev/null +++ b/crates/util/migrations.old/20231007012439_teams.sql @@ -0,0 +1,15 @@ +create table if not exists teams +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + icon varchar(255) null, + name varchar(255) not null, + owner_user_id numeric( + 20, 0 + ) null constraint chk_owner_user_id_range check ( + owner_user_id >= 0 and owner_user_id <= 18446744073709551615 + ), + constraint fk_13f00abf7cb6096c43ecaf8c108 + foreign key (owner_user_id) references users (id) +); diff --git a/crates/util/migrations.old/20231007012456_applications.sql b/crates/util/migrations.old/20231007012456_applications.sql new file mode 100644 index 0000000..a955baf --- /dev/null +++ b/crates/util/migrations.old/20231007012456_applications.sql @@ -0,0 +1,52 @@ +create table if not exists applications +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + name varchar(255) not null, + icon varchar(255) null, + description varchar(255) null, + summary varchar(255) null, + type text null, + hook boolean not null, + bot_public boolean not null, + bot_require_code_grant boolean not null, + verify_key numeric(20, 0) not null constraint chk_verify_key_range check ( + verify_key >= 0 and verify_key <= 18446744073709551615 + ), + flags int not null, + redirect_uris text null, + rpc_application_state int null, + store_application_state int null, + verification_state int null, + interactions_endpoint_url varchar(255) null, + integration_public boolean null, + integration_require_code_grant boolean null, + discoverability_state int null, + discovery_eligibility_flags int null, + tags text null, + cover_image varchar(255) null, + install_params text null, + terms_of_service_url varchar(255) null, + privacy_policy_url varchar(255) null, + owner_id numeric(20, 0) null constraint chk_owner_id_range check ( + owner_id >= 0 and owner_id <= 18446744073709551615 + ), + bot_user_id numeric(20, 0) null constraint chk_bot_user_id_range check ( + bot_user_id >= 0 and bot_user_id <= 18446744073709551615 + ), + team_id numeric(20, 0) null constraint chk_team_id_range check ( + team_id >= 0 and team_id <= 18446744073709551615 + ), + constraint rel_2ce5a55796fe4c2f77ece57a64 + unique (bot_user_id), + constraint fk_2ce5a55796fe4c2f77ece57a647 + foreign key (bot_user_id) references users (id) + on delete cascade, + constraint fk_a36ed02953077f408d0f3ebc424 + foreign key (team_id) references teams (id) + on delete cascade, + constraint fk_e57508958bf92b9d9d25231b5e8 + foreign key (owner_id) references users (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012505_team_members.sql b/crates/util/migrations.old/20231007012505_team_members.sql new file mode 100644 index 0000000..afbdb56 --- /dev/null +++ b/crates/util/migrations.old/20231007012505_team_members.sql @@ -0,0 +1,20 @@ +create table if not exists team_members +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + membership_state int not null, + permissions text not null, + team_id numeric(20, 0) null constraint chk_team_id_range check ( + team_id >= 0 and team_id <= 18446744073709551615 + ), + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + constraint fk_c2bf4967c8c2a6b845dadfbf3d4 + foreign key (user_id) references users (id) + on delete cascade, + constraint fk_fdad7d5768277e60c40e01cdcea + foreign key (team_id) references teams (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012517_templates.sql b/crates/util/migrations.old/20231007012517_templates.sql new file mode 100644 index 0000000..833196a --- /dev/null +++ b/crates/util/migrations.old/20231007012517_templates.sql @@ -0,0 +1,32 @@ +create table if not exists templates +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + code varchar(255) not null, + name varchar(255) not null, + description varchar(255) null, + usage_count int null, + creator_id numeric(20, 0) null constraint chk_creator_id_range check ( + creator_id >= 0 and creator_id <= 18446744073709551615 + ), + created_at timestamp not null, + updated_at timestamp not null, + source_guild_id numeric( + 20, 0 + ) null constraint chk_source_guild_id_range check ( + source_guild_id >= 0 and source_guild_id <= 18446744073709551615 + ), + serialized_source_guild text not null, + constraint idx_be38737bf339baf63b1daeffb5 + unique (code), + constraint fk_445d00eaaea0e60a017a5ed0c11 + foreign key (source_guild_id) references guilds (id) + on delete cascade, + constraint fk_d7374b7f8f5fbfdececa4fb62e1 + foreign key (creator_id) references users (id) +); + +alter table guilds +add constraint fk_e2a2f873a64a5cf62526de42325 +foreign key (template_id) references templates (id); diff --git a/crates/util/migrations.old/20231007012542_valid_registration_tokens.sql b/crates/util/migrations.old/20231007012542_valid_registration_tokens.sql new file mode 100644 index 0000000..d93b20c --- /dev/null +++ b/crates/util/migrations.old/20231007012542_valid_registration_tokens.sql @@ -0,0 +1,7 @@ +create table if not exists valid_registration_tokens +( + token varchar(255) not null + primary key, + created_at timestamp not null, + expires_at timestamp not null +); diff --git a/crates/util/migrations.old/20231007012555_voice_states.sql b/crates/util/migrations.old/20231007012555_voice_states.sql new file mode 100644 index 0000000..e815ce9 --- /dev/null +++ b/crates/util/migrations.old/20231007012555_voice_states.sql @@ -0,0 +1,36 @@ +create table if not exists voice_states +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + session_id numeric(20, 0) not null constraint chk_session_id_range check ( + session_id >= 0 and session_id <= 18446744073709551615 + ), + token varchar(255) null, + deaf boolean not null, + mute boolean not null, + self_deaf boolean not null, + self_mute boolean not null, + self_stream boolean null, + self_video boolean not null, + suppress boolean not null, + request_to_speak_timestamp timestamp null, + constraint fk_03779ef216d4b0358470d9cb748 + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_5fe1d5f931a67e85039c640001b + foreign key (user_id) references users (id) + on delete cascade, + constraint fk_9f8d389866b40b6657edd026dd4 + foreign key (channel_id) references channels (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012609_webhooks.sql b/crates/util/migrations.old/20231007012609_webhooks.sql new file mode 100644 index 0000000..df38fcb --- /dev/null +++ b/crates/util/migrations.old/20231007012609_webhooks.sql @@ -0,0 +1,44 @@ +create table if not exists webhooks +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + type int not null, + name varchar(255) null, + avatar varchar(255) null, + token varchar(255) null, + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + application_id numeric( + 20, 0 + ) null constraint chk_application_id_range check ( + application_id >= 0 and application_id <= 18446744073709551615 + ), + user_id numeric(20, 0) null constraint chk_user_id_range check ( + user_id >= 0 and user_id <= 18446744073709551615 + ), + source_guild_id numeric( + 20, 0 + ) null constraint chk_source_guild_id_range check ( + source_guild_id >= 0 and source_guild_id <= 18446744073709551615 + ), + constraint fk_0d523f6f997c86e052c49b1455f + foreign key (user_id) references users (id) + on delete cascade, + constraint fk_3a285f4f49c40e0706d3018bc9f + foreign key (source_guild_id) references guilds (id) + on delete cascade, + constraint fk_487a7af59d189f744fe394368fc + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_c3e5305461931763b56aa905f1c + foreign key (application_id) references applications (id) + on delete cascade, + constraint fk_df528cf77e82f8032230e7e37d8 + foreign key (channel_id) references channels (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012620_messages.sql b/crates/util/migrations.old/20231007012620_messages.sql new file mode 100644 index 0000000..70c36ab --- /dev/null +++ b/crates/util/migrations.old/20231007012620_messages.sql @@ -0,0 +1,67 @@ +create table if not exists messages +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + guild_id numeric(20, 0) null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + author_id numeric(20, 0) null constraint chk_author_id_range check ( + author_id >= 0 and author_id <= 18446744073709551615 + ), + member_id numeric(20, 0) null constraint chk_member_id_range check ( + member_id >= 0 and member_id <= 18446744073709551615 + ), + webhook_id numeric(20, 0) null constraint chk_webhook_id_range check ( + webhook_id >= 0 and webhook_id <= 18446744073709551615 + ), + application_id numeric( + 20, 0 + ) null constraint chk_application_id_range check ( + application_id >= 0 and application_id <= 18446744073709551615 + ), + content varchar(255) null, + timestamp timestamp(6) default current_timestamp(6) not null, + edited_timestamp timestamp null, + tts boolean null, + mention_everyone boolean null, + embeds text not null, + reactions text not null, + nonce text null, + pinned boolean null, + type int not null, + activity text null, + flags int null, + message_reference text null, + interaction text null, + components text null, + message_reference_id numeric( + 20, 0 + ) null constraint chk_message_reference_id_range check ( + message_reference_id >= 0 + and message_reference_id <= 18446744073709551615 + ), + constraint idx_3ed7a60fb7dbe04e1ba9332a8b + unique (channel_id, id), + constraint fk_05535bc695e9f7ee104616459d3 + foreign key (author_id) references users (id) + on delete cascade, + constraint fk_5d3ec1cb962de6488637fd779d6 + foreign key (application_id) references applications (id), + constraint fk_61a92bb65b302a76d9c1fcd3174 + foreign key (message_reference_id) references messages (id), + constraint fk_86b9109b155eb70c0a2ca3b4b6d + foreign key (channel_id) references channels (id) + on delete cascade, + constraint fk_b0525304f2262b7014245351c76 + foreign key (member_id) references users (id) + on delete cascade, + constraint fk_b193588441b085352a4c0109423 + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint fk_f83c04bcf1df4e5c0e7a52ed348 + foreign key (webhook_id) references webhooks (id) +); diff --git a/crates/util/migrations.old/20231007012640_attachments.sql b/crates/util/migrations.old/20231007012640_attachments.sql new file mode 100644 index 0000000..0bbdc7c --- /dev/null +++ b/crates/util/migrations.old/20231007012640_attachments.sql @@ -0,0 +1,19 @@ +create table if not exists attachments +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + filename varchar(255) not null, + size int not null, + url varchar(255) not null, + proxy_url varchar(255) not null, + height int null, + width int null, + content_type varchar(255) null, + message_id numeric(20, 0) null constraint chk_message_id_range check ( + message_id >= 0 and message_id <= 18446744073709551615 + ), + constraint fk_623e10eec51ada466c5038979e3 + foreign key (message_id) references messages (id) + on delete cascade +); diff --git a/crates/util/migrations.old/20231007012656_message_channel_mentions.sql b/crates/util/migrations.old/20231007012656_message_channel_mentions.sql new file mode 100644 index 0000000..9bc4783 --- /dev/null +++ b/crates/util/migrations.old/20231007012656_message_channel_mentions.sql @@ -0,0 +1,22 @@ +create table if not exists message_channel_mentions +( + messagesid numeric(20, 0) not null constraint chk_messages_id_range check ( + messagesid >= 0 and messagesid <= 18446744073709551615 + ), + channelsid numeric(20, 0) not null constraint chk_channels_id_range check ( + channelsid >= 0 and channelsid <= 18446744073709551615 + ), + primary key (messagesid, channelsid), + constraint fk_2a27102ecd1d81b4582a4360921 + foreign key (messagesid) references messages (id) + on update cascade on delete cascade, + constraint fk_bdb8c09e1464cabf62105bf4b9d + foreign key (channelsid) references channels (id) + on update cascade on delete cascade +); + +create index if not exists idx_2a27102ecd1d81b4582a436092 +on message_channel_mentions (messagesid); + +create index if not exists idx_bdb8c09e1464cabf62105bf4b9 +on message_channel_mentions (channelsid); diff --git a/crates/util/migrations.old/20231007012735_message_role_mentions.sql b/crates/util/migrations.old/20231007012735_message_role_mentions.sql new file mode 100644 index 0000000..00e6d0a --- /dev/null +++ b/crates/util/migrations.old/20231007012735_message_role_mentions.sql @@ -0,0 +1,22 @@ +create table if not exists message_role_mentions +( + messagesid numeric(20, 0) not null constraint chk_messages_id_range check ( + messagesid >= 0 and messagesid <= 18446744073709551615 + ), + rolesid numeric(20, 0) not null constraint chk_roles_id_range check ( + rolesid >= 0 and rolesid <= 18446744073709551615 + ), + primary key (messagesid, rolesid), + constraint fk_29d63eb1a458200851bc37d074b + foreign key (rolesid) references roles (id) + on update cascade on delete cascade, + constraint fk_a8242cf535337a490b0feaea0b4 + foreign key (messagesid) references messages (id) + on update cascade on delete cascade +); + +create index if not exists idx_29d63eb1a458200851bc37d074 +on message_role_mentions (rolesid); + +create index if not exists idx_a8242cf535337a490b0feaea0b +on message_role_mentions (messagesid); diff --git a/crates/util/migrations.old/20231007012751_message_stickers.sql b/crates/util/migrations.old/20231007012751_message_stickers.sql new file mode 100644 index 0000000..3bc80a3 --- /dev/null +++ b/crates/util/migrations.old/20231007012751_message_stickers.sql @@ -0,0 +1,22 @@ +create table if not exists message_stickers +( + messagesid numeric(20, 0) not null constraint chk_messages_id_range check ( + messagesid >= 0 and messagesid <= 18446744073709551615 + ), + stickersid numeric(20, 0) not null constraint chk_stickers_id_range check ( + stickersid >= 0 and stickersid <= 18446744073709551615 + ), + primary key (messagesid, stickersid), + constraint fk_40bb6f23e7cc133292e92829d28 + foreign key (messagesid) references messages (id) + on update cascade on delete cascade, + constraint fk_e22a70819d07659c7a71c112a1f + foreign key (stickersid) references stickers (id) + on update cascade on delete cascade +); + +create index if not exists idx_40bb6f23e7cc133292e92829d2 +on message_stickers (messagesid); + +create index if not exists idx_e22a70819d07659c7a71c112a1 +on message_stickers (stickersid); diff --git a/crates/util/migrations.old/20231007012803_message_user_mentions.sql b/crates/util/migrations.old/20231007012803_message_user_mentions.sql new file mode 100644 index 0000000..331aec8 --- /dev/null +++ b/crates/util/migrations.old/20231007012803_message_user_mentions.sql @@ -0,0 +1,28 @@ +create table if not exists message_user_mentions +( + messagesid numeric(20, 0) not null constraint chk_messages_id_range check ( + messagesid >= 0 and messagesid <= 18446744073709551615 + ), + usersid numeric(20, 0) not null constraint chk_users_id_range check ( + usersid >= 0 and usersid <= 18446744073709551615 + ), + primary key (messagesid, usersid), + constraint fk_a343387fc560ef378760681c236 + foreign key (messagesid) references messages (id) + on update cascade on delete cascade, + constraint fk_b831eb18ceebd28976239b1e2f8 + foreign key (usersid) references users (id) + on update cascade on delete cascade +); + +create index if not exists idx_a343387fc560ef378760681c23 +on message_user_mentions (messagesid); + +create index if not exists idx_b831eb18ceebd28976239b1e2f +on message_user_mentions (usersid); + +create index if not exists idx_05535bc695e9f7ee104616459d +on messages (author_id); + +create index if not exists idx_86b9109b155eb70c0a2ca3b4b6 +on messages (channel_id); diff --git a/crates/util/migrations.old/20240605191045_guild_scheduled_events.sql b/crates/util/migrations.old/20240605191045_guild_scheduled_events.sql new file mode 100644 index 0000000..773c248 --- /dev/null +++ b/crates/util/migrations.old/20240605191045_guild_scheduled_events.sql @@ -0,0 +1,47 @@ +create table if not exists guild_scheduled_events +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + guild_id numeric(20, 0) not null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + creator_id numeric(20, 0) null constraint chk_creator_id_range check ( + creator_id >= 0 and creator_id <= 18446744073709551615 + ), + name varchar(100) null, + description text null, + scheduled_start_time timestamp default CURRENT_TIMESTAMP not null, + scheduled_end_time timestamp null, + privacy_level int not null, + status int not null, + entity_type int not null, + entity_id numeric(20, 0) null constraint chk_entity_id_range check ( + entity_id >= 0 and entity_id <= 18446744073709551615 + ), + location varchar(100) null, + user_count int default 0 not null, + image text null, + constraint guild_scheduled_event_channels_id_fk + foreign key (channel_id) references channels (id), + constraint guild_scheduled_event_guilds_id_fk + foreign key (guild_id) references guilds (id), + constraint guild_scheduled_event_users_id_fk + foreign key (creator_id) references users (id) +); + +create or replace function UPDATE_SCHEDULED_START_TIME() +returns trigger as $$ +begin + NEW.scheduled_start_time := CURRENT_TIMESTAMP; + return NEW; +end; +$$ language plpgsql; + +create trigger update_scheduled_start_time_trigger +before update on guild_scheduled_events +for each row +execute function UPDATE_SCHEDULED_START_TIME(); diff --git a/crates/util/migrations.old/20240605192122_stage_instances.sql b/crates/util/migrations.old/20240605192122_stage_instances.sql new file mode 100644 index 0000000..598d7b6 --- /dev/null +++ b/crates/util/migrations.old/20240605192122_stage_instances.sql @@ -0,0 +1,32 @@ +create table if not exists stage_instances +( + id numeric(20, 0) not null constraint chk_id_range check ( + id >= 0 and id <= 18446744073709551615 + ) primary key, + guild_id numeric(20, 0) not null constraint chk_guild_id_range check ( + guild_id >= 0 and guild_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) not null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + topic varchar(120) not null, + privacy_level int not null, + invite_code varchar(16) null, + discoverable_disabled boolean not null default false, + guild_scheduled_event_id numeric( + 20, 0 + ) null constraint chk_guild_scheduled_event_id_range check ( + guild_scheduled_event_id >= 0 + and guild_scheduled_event_id <= 18446744073709551615 + ), + constraint stage_instances_channels_id_fk + foreign key (channel_id) references channels (id) + on delete cascade, + constraint stage_instances_guilds_id_fk + foreign key (guild_id) references guilds (id) + on delete cascade, + constraint stage_instances_guild_scheduled_events_id_fk + foreign key (guild_scheduled_event_id) references guild_scheduled_events ( + id + ) +); diff --git a/crates/util/migrations.old/20240607211359_read_states_add_message_fk.sql b/crates/util/migrations.old/20240607211359_read_states_add_message_fk.sql new file mode 100644 index 0000000..5cc4627 --- /dev/null +++ b/crates/util/migrations.old/20240607211359_read_states_add_message_fk.sql @@ -0,0 +1,8 @@ +alter table read_states +add constraint read_states_messages_id_fk +foreign key (last_message_id) references messages (id) +on delete cascade; +alter table read_states +add constraint read_states_users_id_fk_2 +foreign key (notifications_cursor) references messages (id) +on delete cascade; diff --git a/crates/util/migrations.old/20240619142920_channel_followers.sql b/crates/util/migrations.old/20240619142920_channel_followers.sql new file mode 100644 index 0000000..c5f2dba --- /dev/null +++ b/crates/util/migrations.old/20240619142920_channel_followers.sql @@ -0,0 +1,16 @@ +create table channel_followers +( + webhook_id numeric(20, 0) not null constraint chk_webhook_id_range check ( + webhook_id >= 0 and webhook_id <= 18446744073709551615 + ), + channel_id numeric(20, 0) not null constraint chk_channel_id_range check ( + channel_id >= 0 and channel_id <= 18446744073709551615 + ), + primary key (channel_id, webhook_id), + constraint channel_followers_channels_id_fk + foreign key (channel_id) references channels (id) + on delete cascade, + constraint channel_followers_webhooks_id_fk + foreign key (webhook_id) references webhooks (id) + on delete cascade +); diff --git a/crates/util/migrations/00000_utils.sql b/crates/util/migrations/00000_utils.sql new file mode 100644 index 0000000..3a39722 --- /dev/null +++ b/crates/util/migrations/00000_utils.sql @@ -0,0 +1,21 @@ +-- # tzone table +-- https://postgres.cz/wiki/PostgreSQL_SQL_Tricks_III#:~:text=Domain%20for%20time-,zone,-David%20E.%20Wheleer +CREATE OR REPLACE FUNCTION is_timezone( + tz TEXT +) RETURNS BOOLEAN AS $$ BEGIN PERFORM now() AT TIME ZONE tz; +RETURN TRUE; +EXCEPTION +WHEN invalid_parameter_value THEN RETURN FALSE; +END; +$$ LANGUAGE plpgsql STABLE; +CREATE DOMAIN timezone AS TEXT CHECK (is_timezone(value)); +CREATE TABLE IF NOT EXISTS tzone ( + tzone_name TEXT PRIMARY KEY CONSTRAINT chk_is_timzeone CHECK ( + is_timezone(tzone_name) + ) +); +INSERT INTO tzone (tzone_name) +SELECT name +FROM pg_timezone_names; +-- # entity type enum +CREATE TYPE entity_type AS ENUM ('actor', 'guild', 'channel', 'message'); diff --git a/crates/util/migrations/00001_users.sql b/crates/util/migrations/00001_users.sql new file mode 100644 index 0000000..487222e --- /dev/null +++ b/crates/util/migrations/00001_users.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS users ( + local_name text NOT NULL PRIMARY KEY, + display_name text NULL, + pronouns varchar(32) NULL, + about varchar(1000) NULL, + avatar varchar(255) NULL, + availability smallint NOT NULL DEFAULT 0 CONSTRAINT chk_availability CHECK ( + availability >= 0 + AND availability <= 3 + ), + status varchar(50) NULL, + timezone text REFERENCES tzone (tzone_name) NULL +); diff --git a/crates/util/migrations/00002_guilds.sql b/crates/util/migrations/00002_guilds.sql new file mode 100644 index 0000000..b61a500 --- /dev/null +++ b/crates/util/migrations/00002_guilds.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS guilds ( + id varchar(64) PRIMARY KEY NOT NULL, + display_name varchar(64) NOT NULL, + description varchar(1000) NULL, + icon varchar(255) NULL, + owner_id text NULL, + CONSTRAINT fk_owner_id FOREIGN KEY (owner_id) REFERENCES users (local_name), + created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/crates/util/migrations/00003_channel_data.sql b/crates/util/migrations/00003_channel_data.sql new file mode 100644 index 0000000..1f2b3c8 --- /dev/null +++ b/crates/util/migrations/00003_channel_data.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS channel_data ( + id bigserial PRIMARY KEY, + type smallint NOT NULL DEFAULT 0 CONSTRAINT chk_type CHECK ( + type >= 0 + AND type <= 3 + ), + name varchar(64) NOT NULL, + description text NULL +); diff --git a/crates/util/migrations/00004_permissions.sql b/crates/util/migrations/00004_permissions.sql new file mode 100644 index 0000000..9ec6d85 --- /dev/null +++ b/crates/util/migrations/00004_permissions.sql @@ -0,0 +1,21 @@ +CREATE TYPE permission_override_value AS ENUM ( + 'allow', 'unchanged', 'disallow' +); +CREATE TYPE permission_override_type AS ENUM ( + 'channel.view', + 'channel.write', + 'channel.modify', + 'channel.voice.speak', + 'channel.voice.mute_others', + 'channel.voice.deafen_others', + 'channel.voice.disconnect_others', + 'channel.send_attachments' +); +CREATE TYPE permission_override AS ( + type permission_override_type, + value permission_override_value +); +CREATE TYPE permission_overrides AS ( + entity text, + overrides permission_override [] +); diff --git a/crates/util/migrations/00005_channels.sql b/crates/util/migrations/00005_channels.sql new file mode 100644 index 0000000..86a682c --- /dev/null +++ b/crates/util/migrations/00005_channels.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS channels ( + id uuid NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(), + position integer NOT NULL, + parent varchar(255) NOT NULL, + parent_type entity_type NOT NULL, + permission_overrides permission_overrides [] NULL, + channel_data_reference bigint UNIQUE NULL, + channel_data_encrypted text NULL, + CONSTRAINT fk_channel_data FOREIGN KEY ( + channel_data_reference + ) REFERENCES channel_data (id) ON DELETE CASCADE +); + +-- Ensure that either encrypted data is present, or that there exists a foreign key +-- to the channel_data table. +ALTER TABLE channels +ADD CONSTRAINT either_data_reference_or_encrypted_data +CHECK (channel_data_reference IS NOT null OR channel_data_encrypted IS NOT null); diff --git a/crates/util/migrations/00006_rawr.sql b/crates/util/migrations/00006_rawr.sql new file mode 100644 index 0000000..c8653cc --- /dev/null +++ b/crates/util/migrations/00006_rawr.sql @@ -0,0 +1 @@ +CREATE TABLE IF NOT EXISTS rawr_content (); diff --git a/crates/util/migrations/00007_emoji.sql b/crates/util/migrations/00007_emoji.sql new file mode 100644 index 0000000..e69de29 diff --git a/crates/util/migrations/00008_messages.sql b/crates/util/migrations/00008_messages.sql new file mode 100644 index 0000000..77804da --- /dev/null +++ b/crates/util/migrations/00008_messages.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS embeds (); +CREATE TABLE IF NOT EXISTS reactions (); + +CREATE TABLE IF NOT EXISTS message_data ( + id BIGSERIAL PRIMARY KEY, + content TEXT NULL, + -- TODO: Make these proper types/fk's + attachments TEXT [] NULL, + embeds TEXT [] NULL, + reactions TEXT [] NULL +); + +CREATE TABLE IF NOT EXISTS messages ( + version NUMERIC(20, 0) NOT NULL CONSTRAINT chk_range CHECK (version >= 0 AND version <= 18446744073709551615), + uid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(), + author TEXT NOT NULL, -- TODO: fk constraint + timestamp TIMESTAMP +); diff --git a/crates/util/migrations/20231007011602_categories.sql b/crates/util/migrations/20231007011602_categories.sql deleted file mode 100644 index 41fd88e..0000000 --- a/crates/util/migrations/20231007011602_categories.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table if not exists categories -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - name varchar(255) null, - localizations text not null, - is_primary boolean null -); diff --git a/crates/util/migrations/20231007011617_client_release.sql b/crates/util/migrations/20231007011617_client_release.sql deleted file mode 100644 index 7997d33..0000000 --- a/crates/util/migrations/20231007011617_client_release.sql +++ /dev/null @@ -1,10 +0,0 @@ -create table if not exists client_release -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - name varchar(255) not null, - pub_date timestamp not null, - url varchar(255) not null, - platform varchar(255) not null, - enabled boolean not null, - notes varchar(255) null -); diff --git a/crates/util/migrations/20231007011705_embed_cache.sql b/crates/util/migrations/20231007011705_embed_cache.sql deleted file mode 100644 index cffcb6a..0000000 --- a/crates/util/migrations/20231007011705_embed_cache.sql +++ /dev/null @@ -1,6 +0,0 @@ -create table if not exists embed_cache -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - url varchar(255) not null, - embed text not null -); diff --git a/crates/util/migrations/20231007011719_rate_limits.sql b/crates/util/migrations/20231007011719_rate_limits.sql deleted file mode 100644 index 861df46..0000000 --- a/crates/util/migrations/20231007011719_rate_limits.sql +++ /dev/null @@ -1,8 +0,0 @@ -create table if not exists rate_limits -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - executor_id numeric(20, 0) not null constraint chk_executor_id_range check (executor_id >= 0 AND executor_id <= 18446744073709551615), - hits int not null, - blocked boolean not null, - expires_at timestamp not null -); diff --git a/crates/util/migrations/20231007011737_security_settings.sql b/crates/util/migrations/20231007011737_security_settings.sql deleted file mode 100644 index 638a064..0000000 --- a/crates/util/migrations/20231007011737_security_settings.sql +++ /dev/null @@ -1,10 +0,0 @@ -create table if not exists security_settings -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - encryption_permission_mask int not null, - allowed_algorithms text not null, - current_algorithm varchar(255) not null, - used_since_message varchar(255) null -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011751_sticker_packs.sql b/crates/util/migrations/20231007011751_sticker_packs.sql deleted file mode 100644 index 6f29e9f..0000000 --- a/crates/util/migrations/20231007011751_sticker_packs.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table if not exists sticker_packs -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - name varchar(255) not null, - description varchar(255) null, - banner_asset_id numeric(20, 0) null constraint chk_banner_asset_id_range check (banner_asset_id >= 0 AND banner_asset_id <= 18446744073709551615), - cover_sticker_id numeric(20, 0) null constraint chk_cover_sticker_id_range check (cover_sticker_id >= 0 AND cover_sticker_id <= 18446744073709551615), - coverStickerId numeric(20, 0) null constraint chk_coverStickerId_range check (coverStickerId >= 0 AND coverStickerId <= 18446744073709551615) -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011756_user_settings.sql b/crates/util/migrations/20231007011756_user_settings.sql deleted file mode 100644 index 43e0bff..0000000 --- a/crates/util/migrations/20231007011756_user_settings.sql +++ /dev/null @@ -1,38 +0,0 @@ -CREATE SEQUENCE user_settings_index_seq; - -CREATE TABLE IF NOT EXISTS user_settings -( - index numeric(20, 0) not null default nextval('user_settings_index_seq') constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) primary key, - afk_timeout int null, - allow_accessibility_detection boolean null, - animate_emoji boolean null, - animate_stickers int null, - contact_sync_enabled boolean null, - convert_emoticons boolean null, - custom_status text null, - default_guilds_restricted boolean null, - detect_platform_accounts boolean null, - developer_mode boolean null, - disable_games_tab boolean null, - enable_tts_command boolean null, - explicit_content_filter int null, - friend_source_flags text null, - gateway_connected boolean null, - gif_auto_play boolean null, - guild_folders text null, - guild_positions text null, - inline_attachment_media boolean null, - inline_embed_media boolean null, - locale varchar(255) null, - message_display_compact boolean null, - native_phone_integration_enabled boolean null, - render_embeds boolean null, - render_reactions boolean null, - restricted_guilds text null, - show_current_game boolean null, - status varchar(255) null, - stream_notifications_enabled boolean null, - theme varchar(255) null, - timezone_offset int null -); - diff --git a/crates/util/migrations/20231007011757_users.sql b/crates/util/migrations/20231007011757_users.sql deleted file mode 100644 index 92a1daf..0000000 --- a/crates/util/migrations/20231007011757_users.sql +++ /dev/null @@ -1,43 +0,0 @@ -create table if not exists users ( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - username varchar(255) not null, - discriminator varchar(255) not null, - avatar varchar(255) null, - accent_color numeric(10, 0) null constraint chk_accent_color check (accent_color >= 0 and accent_color <= 4294967295), - banner varchar(255) null, - theme_colors NUMERIC(3,0)[8] null, - pronouns varchar(255) null, - phone varchar(255) null, - desktop boolean not null default false, - mobile boolean not null default false, - premium boolean not null, - premium_type numeric(5, 0) not null constraint chk_smallint_unsigned check (premium_type >= 0 and premium_type <= 65535), - bot boolean not null default false, - bio varchar(255) not null default '', - system boolean not null default false, - nsfw_allowed boolean not null default false, - mfa_enabled boolean not null default false, - webauthn_enabled boolean not null default false, - totp_secret varchar(255) null, - totp_last_ticket varchar(255) null, - created_at timestamp not null, - premium_since timestamptz null, - verified boolean not null default false, - disabled boolean not null default false, - deleted boolean not null default false, - email varchar(255) null, - flags numeric(20, 0) not null constraint chk_flags_range check (flags >= 0 AND flags <= 18446744073709551615), - public_flags numeric(10, 0) not null constraint chk_int_unsigned check (public_flags >= 0 and public_flags <= 4294967295), - purchased_flags int not null, - premium_usage_flags int not null, - rights numeric(20, 0) not null constraint chk_rights_range check (rights >= 0 AND rights <= 18446744073709551615), - data json not null, - fingerprints text not null, - extended_settings json not null, - settings_index numeric(20, 0) null constraint chk_settings_index_range check (settings_index >= 0 AND settings_index <= 18446744073709551615), - constraint users_settings_index_uindex unique (settings_index), - constraint users_user_settings_index_fk foreign key (settings_index) references user_settings (index), - constraint check_theme_colors_elements check ( - array_length(theme_colors, 1) <= 8 - ) -); diff --git a/crates/util/migrations/20231007011857_audit_logs.sql b/crates/util/migrations/20231007011857_audit_logs.sql deleted file mode 100644 index 42a634f..0000000 --- a/crates/util/migrations/20231007011857_audit_logs.sql +++ /dev/null @@ -1,15 +0,0 @@ -create table if not exists audit_logs -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - action_type int not null, - options text null, - changes text not null, - reason varchar(255) null, - target_id numeric(20, 0) null constraint chk_target_id_range check (target_id >= 0 AND target_id <= 18446744073709551615), - constraint FK_3cd01cd3ae7aab010310d96ac8e - foreign key (target_id) references users (id), - constraint FK_bd2726fd31b35443f2245b93ba0 - foreign key (user_id) references users (id) -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011910_backup_codes.sql b/crates/util/migrations/20231007011910_backup_codes.sql deleted file mode 100644 index c02d9fa..0000000 --- a/crates/util/migrations/20231007011910_backup_codes.sql +++ /dev/null @@ -1,11 +0,0 @@ -create table if not exists backup_codes -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - code varchar(255) not null, - consumed boolean not null, - expired boolean not null, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - constraint FK_70066ea80d2f4b871beda32633b - foreign key (user_id) references users (id) - on delete cascade -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011933_channels.sql b/crates/util/migrations/20231007011933_channels.sql deleted file mode 100644 index 40e534e..0000000 --- a/crates/util/migrations/20231007011933_channels.sql +++ /dev/null @@ -1,39 +0,0 @@ -create table if not exists channels -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - created_at timestamptz not null, - name varchar(255) null, - icon text null, - type int not null, - last_message_id numeric(20, 0) null constraint chk_last_message_id_range check (last_message_id >= 0 AND last_message_id <= 18446744073709551615), - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - parent_id numeric(20, 0) null constraint chk_parent_id check (parent_id >= 0 AND parent_id <= 18446744073709551615), - owner_id numeric(20, 0) null constraint chk_owner_id_range check (owner_id >= 0 AND owner_id <= 18446744073709551615), - last_pin_timestamp int null, - default_auto_archive_duration int null, - position int null, - managed boolean null, - rtc_region varchar(255) null, - permission_overwrites text null, - video_quality_mode int null, - bitrate int null, - user_limit int null, - nsfw boolean not null, - rate_limit_per_user int null, - topic varchar(255) null, - retention_policy_id varchar(255) null, - flags int not null, - default_thread_rate_limit_per_user int not null, - default_sort_order numeric(3, 0) null constraint chk_default_sort_order check (default_sort_order >= 0 AND default_sort_order <= 255), - -- v foreign key constraint is added in emojis migration - -- TODO: I am unsure if deserializing a channel object from the database will work with the default_reaction_emoji field. Test it - default_reaction_emoji numeric(20, 0) null constraint chk_default_reaction_emoji check (default_reaction_emoji >= 0 AND default_reaction_emoji <= 18446744073709551615), - default_forum_layout numeric(3, 0) null constraint chk_default_forum_layout check (default_forum_layout >= 0 AND default_forum_layout <= 255), - available_tags jsonb null constraint chk_available_tags check (jsonb_typeof(available_tags) = 'array') default '[]', - applied_tags jsonb null constraint chk_applied_tags check (jsonb_typeof(applied_tags) = 'array') default '[]', - application_id numeric(20, 0) null constraint chk_application_id_range check (application_id >= 0 AND application_id <= 18446744073709551615), - constraint FK_3274522d14af40540b1a883fc80 - foreign key (parent_id) references channels (id), - constraint FK_3873ed438575cce703ecff4fc7b - foreign key (owner_id) references users (id) -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011946_connected_accounts.sql b/crates/util/migrations/20231007011946_connected_accounts.sql deleted file mode 100644 index 6fa08dd..0000000 --- a/crates/util/migrations/20231007011946_connected_accounts.sql +++ /dev/null @@ -1,22 +0,0 @@ -create table if not exists connected_accounts -( - id varchar(255) not null - primary key, - external_id varchar(255) not null, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - friend_sync boolean not null, - name varchar(255) not null, - revoked boolean not null, - show_activity int not null, - type varchar(255) not null, - verified boolean not null, - visibility int not null, - integrations text not null, - metadata text null, - metadata_visibility int not null, - two_way_link boolean not null, - token_data text null, - constraint FK_f47244225a6a1eac04a3463dd90 - foreign key (user_id) references users (id) - on delete cascade -); \ No newline at end of file diff --git a/crates/util/migrations/20231007011956_guilds.sql b/crates/util/migrations/20231007011956_guilds.sql deleted file mode 100644 index e38ba5c..0000000 --- a/crates/util/migrations/20231007011956_guilds.sql +++ /dev/null @@ -1,54 +0,0 @@ - create table if not exists guilds - ( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - afk_channel_id numeric(20, 0) null constraint chk_afk_channel_range check (afk_channel_id >= 0 AND afk_channel_id <= 18446744073709551615), - afk_timeout int null, - banner varchar(255) null, - default_message_notifications int null, - description varchar(255) null, - discovery_splash varchar(255) null, - explicit_content_filter int null, - features jsonb not null, - primary_category_id varchar(255) null, - icon varchar(255) null, - large boolean not null, - max_members int null, - max_presences int null, - max_video_channel_users int null, - member_count int null, - presence_count int null, - template_id numeric(20, 0) null constraint chk_template_range check (template_id >= 0 AND template_id <= 18446744073709551615), - mfa_level int null, - name varchar(255) not null, - owner_id numeric(20, 0) null constraint chk_owner_id_range check (owner_id >= 0 AND owner_id <= 18446744073709551615), - preferred_locale varchar(255) null, - premium_subscription_count int null, - premium_tier int not null, - public_updates_channel_id numeric(20, 0) null constraint check_pub_upd_channel_id check (public_updates_channel_id >= 0 AND public_updates_channel_id <= 18446744073709551615), - rules_channel_id numeric(20, 0) null constraint chk_rules_channel_id check (rules_channel_id >= 0 AND rules_channel_id <= 18446744073709551615), - region varchar(255) null, - splash varchar(255) null, - system_channel_id numeric(20, 0) null constraint chk_system_channel_id check (system_channel_id >= 0 AND system_channel_id <= 18446744073709551615), - system_channel_flags int null, - unavailable boolean not null, - verification_level int null, - welcome_screen jsonb not null, - widget_channel_id numeric(20, 0) null constraint chk_widget_channel_id check (widget_channel_id >= 0 AND widget_channel_id <= 18446744073709551615), - widget_enabled boolean not null, - nsfw_level int null, - nsfw boolean not null, - parent numeric(20, 0) null constraint chk_parent_id check (parent >= 0 AND parent <= 18446744073709551615), - premium_progress_bar_enabled boolean null, - constraint FK_public_updates_channel_id - foreign key (public_updates_channel_id) references channels (id), - constraint FK_rules_channel_id - foreign key (rules_channel_id) references channels (id), - constraint FK_widget_channel_id - foreign key (widget_channel_id) references channels (id), - constraint FK_system_channel_id - foreign key (system_channel_id) references channels (id), - constraint FK_afk_channel_id - foreign key (afk_channel_id) references channels (id), - constraint FK_owner_user_id - foreign key (owner_id) references users (id) - ); \ No newline at end of file diff --git a/crates/util/migrations/20231007012027_bans.sql b/crates/util/migrations/20231007012027_bans.sql deleted file mode 100644 index 63d6f0b..0000000 --- a/crates/util/migrations/20231007012027_bans.sql +++ /dev/null @@ -1,17 +0,0 @@ -create table if not exists bans -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - executor_id numeric(20, 0) null constraint chk_executor_id check (executor_id >= 0 AND executor_id <= 18446744073709551615), - ip varchar(255) not null, - reason varchar(255) null, - constraint FK_07ad88c86d1f290d46748410d58 - foreign key (executor_id) references users (id), - constraint FK_5999e8e449f80a236ff72023559 - foreign key (user_id) references users (id) - on delete cascade, - constraint FK_9d3ab7dd180ebdd245cdb66ecad - foreign key (guild_id) references guilds (id) - on delete cascade -); \ No newline at end of file diff --git a/crates/util/migrations/20231007012049_channels_guild_id_fk.sql b/crates/util/migrations/20231007012049_channels_guild_id_fk.sql deleted file mode 100644 index ede4ca4..0000000 --- a/crates/util/migrations/20231007012049_channels_guild_id_fk.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table channels - add constraint FK_c253dafe5f3a03ec00cd8fb4581 - foreign key (guild_id) references guilds (id) - on delete cascade; \ No newline at end of file diff --git a/crates/util/migrations/20231007012108_emojis.sql b/crates/util/migrations/20231007012108_emojis.sql deleted file mode 100644 index 1e5e01c..0000000 --- a/crates/util/migrations/20231007012108_emojis.sql +++ /dev/null @@ -1,21 +0,0 @@ -create table if not exists emojis -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - animated boolean not null, - available boolean not null, - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - managed boolean not null, - name varchar(255) not null, - require_colons boolean not null, - roles text not null, - groups text null, - constraint FK_4b988e0db89d94cebcf07f598cc - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_fa7ddd5f9a214e28ce596548421 - foreign key (user_id) references users (id) -); - -ALTER TABLE channels -ADD CONSTRAINT FK_emoji_id_emojis_id FOREIGN KEY (default_reaction_emoji) REFERENCES emojis(id); diff --git a/crates/util/migrations/20231007012121_invites.sql b/crates/util/migrations/20231007012121_invites.sql deleted file mode 100644 index e4595ca..0000000 --- a/crates/util/migrations/20231007012121_invites.sql +++ /dev/null @@ -1,30 +0,0 @@ -create table if not exists invites -( - code varchar(255) not null primary key, - type boolean not null, - temporary boolean not null, - uses int not null, - max_uses int not null, - max_age int not null, - created_at timestamp not null, - expires_at timestamp null, - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - inviter_id numeric(20, 0) null constraint chk_inviter_id check (inviter_id >= 0 AND inviter_id <= 18446744073709551615), - target_user_id numeric(20, 0) null constraint chk_target_user_id check (target_user_id >= 0 AND target_user_id <= 18446744073709551615), - target_user_type int null, - vanity_url boolean null, - flags int not null, - constraint FK_11a0d394f8fc649c19ce5f16b59 - foreign key (target_user_id) references users (id) - on delete cascade, - constraint FK_15c35422032e0b22b4ada95f48f - foreign key (inviter_id) references users (id) - on delete cascade, - constraint FK_3f4939aa1461e8af57fea3fb05d - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_6a15b051fe5050aa00a4b9ff0f6 - foreign key (channel_id) references channels (id) - on delete cascade -); \ No newline at end of file diff --git a/crates/util/migrations/20231007012133_members.sql b/crates/util/migrations/20231007012133_members.sql deleted file mode 100644 index 514d151..0000000 --- a/crates/util/migrations/20231007012133_members.sql +++ /dev/null @@ -1,33 +0,0 @@ -CREATE SEQUENCE members_index_seq; - -create table if not exists members -( - index numeric(20, 0) not null default nextval('members_index_seq') constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) primary key, - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615), - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - nick varchar(255) null, - joined_at timestamp not null, - premium_since bigint null, - deaf boolean not null, - mute boolean not null, - pending boolean not null, - settings text not null, - last_message_id numeric(20, 0) null constraint chk_last_message_id_range check (last_message_id >= 0 AND last_message_id <= 18446744073709551615), - joined_by varchar(255) null, - avatar varchar(255) null, - banner varchar(255) null, - bio varchar(255) not null, - theme_colors text null, - pronouns varchar(255) null, - communication_disabled_until timestamp null, - constraint IDX_bb2bf9386ac443afbbbf9f12d3 - unique (id, guild_id), - constraint FK_16aceddd5b89825b8ed6029ad1c - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_28b53062261b996d9c99fa12404 - foreign key (id) references users (id) - on delete cascade -); - -ALTER SEQUENCE members_index_seq OWNED BY members.index; \ No newline at end of file diff --git a/crates/util/migrations/20231007012149_notes.sql b/crates/util/migrations/20231007012149_notes.sql deleted file mode 100644 index c22d568..0000000 --- a/crates/util/migrations/20231007012149_notes.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE SEQUENCE notes_index_seq; - -create table if not exists notes -( - index numeric(20, 0) not null default nextval('notes_index_seq') constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) primary key, - content varchar(256) not null, - author_id numeric(20, 0) null constraint chk_author_id_range check (author_id >= 0 AND author_id <= 18446744073709551615), - target_id numeric(20, 0) null constraint chk_target_id_range check (target_id >= 0 AND target_id <= 18446744073709551615), - constraint IDX_74e6689b9568cc965b8bfc9150 - unique (author_id, target_id), - constraint FK_23e08e5b4481711d573e1abecdc - foreign key (target_id) references users (id) - on delete cascade, - constraint FK_f9e103f8ae67cb1787063597925 - foreign key (author_id) references users (id) - on delete cascade -); \ No newline at end of file diff --git a/crates/util/migrations/20231007012204_read_states.sql b/crates/util/migrations/20231007012204_read_states.sql deleted file mode 100644 index d7a2b1a..0000000 --- a/crates/util/migrations/20231007012204_read_states.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table if not exists read_states -( - channel_id numeric(20, 0) not null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - user_id numeric(20, 0) not null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - last_message_id numeric(20, 0) null constraint chk_last_message_id_range check (last_message_id >= 0 AND last_message_id <= 18446744073709551615), - public_ack varchar(255) null, - notifications_cursor numeric(20, 0) null constraint chk_notifications_cursor_range check (notifications_cursor >= 0 AND notifications_cursor <= 18446744073709551615), - last_pin_timestamp timestamp null, - mention_count int null, - constraint read_states_channel_id_user_id_uindex - unique (channel_id, user_id), - constraint read_states_users_id_fk - foreign key (user_id) references users (id) - on delete cascade, - constraint read_states_channels_id_fk - foreign key (channel_id) references channels (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012219_recipients.sql b/crates/util/migrations/20231007012219_recipients.sql deleted file mode 100644 index c37e28f..0000000 --- a/crates/util/migrations/20231007012219_recipients.sql +++ /dev/null @@ -1,13 +0,0 @@ -create table if not exists recipients -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - channel_id numeric(20, 0) not null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - user_id numeric(20, 0) not null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - closed boolean default false not null, - constraint FK_2f18ee1ba667f233ae86c0ea60e - foreign key (channel_id) references channels (id) - on delete cascade, - constraint FK_6157e8b6ba4e6e3089616481fe2 - foreign key (user_id) references users (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012235_relationships.sql b/crates/util/migrations/20231007012235_relationships.sql deleted file mode 100644 index c03d3e2..0000000 --- a/crates/util/migrations/20231007012235_relationships.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE SEQUENCE relationships_index_seq; - -CREATE TABLE IF NOT EXISTS relationships -( - index numeric(20, 0) not null default nextval('relationships_index_seq') constraint chk_index_range check (index >= 0 AND index <= 18446744073709551615) primary key, - from_id numeric(20, 0) not null constraint chk_from_id_range check (from_id >= 0 AND from_id <= 18446744073709551615), - to_id numeric(20, 0) not null constraint chk_to_id_range check (to_id >= 0 AND to_id <= 18446744073709551615), - nickname varchar(255) null, - type numeric(3, 0) not null constraint chk_type_range check (type >= 0 AND type <= 255), - since timestamptz null default now(), - constraint FK_unique_relationships - unique (from_id, to_id), - constraint FK_from_id_references_users_id - foreign key (from_id) references users (id) - on delete cascade, - constraint FK_to_id_references_users_id - foreign key (to_id) references users (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012255_roles.sql b/crates/util/migrations/20231007012255_roles.sql deleted file mode 100644 index b2225fa..0000000 --- a/crates/util/migrations/20231007012255_roles.sql +++ /dev/null @@ -1,19 +0,0 @@ -create table if not exists roles -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - color int not null, - hoist boolean not null, - managed boolean not null, - mentionable boolean not null, - name varchar(255) not null, - permissions varchar(255) not null, - position int not null, - icon varchar(255) null, - unicode_emoji varchar(255) null, - tags text null, - flags int default 0 not null, - constraint FK_c32c1ab1c4dc7dcb0278c4b1b8b - foreign key (guild_id) references guilds (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012306_member_roles.sql b/crates/util/migrations/20231007012306_member_roles.sql deleted file mode 100644 index 61e4e44..0000000 --- a/crates/util/migrations/20231007012306_member_roles.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE SEQUENCE member_roles_index_seq; - -create table if not exists member_roles -( - index numeric(20, 0) not null constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) unique, - role_id numeric(20, 0) not null constraint chk_role_id_range check (role_id >= 0 AND role_id <= 18446744073709551615), - primary key (index, role_id), - constraint FK_5d7ddc8a5f9c167f548625e772e - foreign key (index) references members (index) - on update cascade on delete cascade, - constraint FK_e9080e7a7997a0170026d5139c1 - foreign key (role_id) references roles (id) - on update cascade on delete cascade -); - -create index if not exists IDX_e9080e7a7997a0170026d5139c - on member_roles (role_id); - -ALTER SEQUENCE member_roles_index_seq OWNED BY member_roles.index; diff --git a/crates/util/migrations/20231007012332_security_keys.sql b/crates/util/migrations/20231007012332_security_keys.sql deleted file mode 100644 index 726796f..0000000 --- a/crates/util/migrations/20231007012332_security_keys.sql +++ /dev/null @@ -1,12 +0,0 @@ -create table if not exists security_keys -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - key_id numeric(20, 0) not null constraint chk_key_id_range check (key_id >= 0 AND key_id <= 18446744073709551615), - public_key varchar(255) not null, - counter int not null, - name varchar(255) not null, - constraint FK_24c97d0771cafedce6d7163eaad - foreign key (user_id) references users (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012343_sessions.sql b/crates/util/migrations/20231007012343_sessions.sql deleted file mode 100644 index f6091f8..0000000 --- a/crates/util/migrations/20231007012343_sessions.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE SEQUENCE sessions_index_seq; - -create table if not exists sessions -( - index numeric(20, 0) not null default nextval('user_settings_index_seq') constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) primary key, - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - session_id numeric(20, 0) not null constraint chk_session_id_range check (session_id >= 0 AND session_id <= 18446744073709551615), - activities text null, - client_info text not null, - status varchar(255) not null, - constraint FK_085d540d9f418cfbdc7bd55bb19 - foreign key (user_id) references users (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012359_stickers.sql b/crates/util/migrations/20231007012359_stickers.sql deleted file mode 100644 index e0ddc11..0000000 --- a/crates/util/migrations/20231007012359_stickers.sql +++ /dev/null @@ -1,26 +0,0 @@ -create table if not exists stickers -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - name varchar(255) not null, - description varchar(255) null, - available boolean null, - tags varchar(255) null, - pack_id numeric(20, 0) null constraint chk_pack_id_range check (pack_id >= 0 AND pack_id <= 18446744073709551615), - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - type int not null, - format_type int not null, - constraint FK_193d551d852aca5347ef5c9f205 - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_8f4ee73f2bb2325ff980502e158 - foreign key (user_id) references users (id) - on delete cascade, - constraint FK_e7cfa5cefa6661b3fb8fda8ce69 - foreign key (pack_id) references sticker_packs (id) - on delete cascade -); - -alter table sticker_packs - add constraint FK_448fafba4355ee1c837bbc865f1 - foreign key (coverStickerId) references stickers (id); diff --git a/crates/util/migrations/20231007012439_teams.sql b/crates/util/migrations/20231007012439_teams.sql deleted file mode 100644 index f2da761..0000000 --- a/crates/util/migrations/20231007012439_teams.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table if not exists teams -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - icon varchar(255) null, - name varchar(255) not null, - owner_user_id numeric(20, 0) null constraint chk_owner_user_id_range check (owner_user_id >= 0 AND owner_user_id <= 18446744073709551615), - constraint FK_13f00abf7cb6096c43ecaf8c108 - foreign key (owner_user_id) references users (id) -); diff --git a/crates/util/migrations/20231007012456_applications.sql b/crates/util/migrations/20231007012456_applications.sql deleted file mode 100644 index 34c452b..0000000 --- a/crates/util/migrations/20231007012456_applications.sql +++ /dev/null @@ -1,42 +0,0 @@ -create table if not exists applications -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - name varchar(255) not null, - icon varchar(255) null, - description varchar(255) null, - summary varchar(255) null, - type text null, - hook boolean not null, - bot_public boolean not null, - bot_require_code_grant boolean not null, - verify_key numeric(20, 0) not null constraint chk_verify_key_range check (verify_key >= 0 AND verify_key <= 18446744073709551615), - flags int not null, - redirect_uris text null, - rpc_application_state int null, - store_application_state int null, - verification_state int null, - interactions_endpoint_url varchar(255) null, - integration_public boolean null, - integration_require_code_grant boolean null, - discoverability_state int null, - discovery_eligibility_flags int null, - tags text null, - cover_image varchar(255) null, - install_params text null, - terms_of_service_url varchar(255) null, - privacy_policy_url varchar(255) null, - owner_id numeric(20, 0) null constraint chk_owner_id_range check (owner_id >= 0 AND owner_id <= 18446744073709551615), - bot_user_id numeric(20, 0) null constraint chk_bot_user_id_range check (bot_user_id >= 0 AND bot_user_id <= 18446744073709551615), - team_id numeric(20, 0) null constraint chk_team_id_range check (team_id >= 0 AND team_id <= 18446744073709551615), - constraint REL_2ce5a55796fe4c2f77ece57a64 - unique (bot_user_id), - constraint FK_2ce5a55796fe4c2f77ece57a647 - foreign key (bot_user_id) references users (id) - on delete cascade, - constraint FK_a36ed02953077f408d0f3ebc424 - foreign key (team_id) references teams (id) - on delete cascade, - constraint FK_e57508958bf92b9d9d25231b5e8 - foreign key (owner_id) references users (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012505_team_members.sql b/crates/util/migrations/20231007012505_team_members.sql deleted file mode 100644 index ce16ecf..0000000 --- a/crates/util/migrations/20231007012505_team_members.sql +++ /dev/null @@ -1,14 +0,0 @@ -create table if not exists team_members -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - membership_state int not null, - permissions text not null, - team_id numeric(20, 0) null constraint chk_team_id_range check (team_id >= 0 AND team_id <= 18446744073709551615), - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - constraint FK_c2bf4967c8c2a6b845dadfbf3d4 - foreign key (user_id) references users (id) - on delete cascade, - constraint FK_fdad7d5768277e60c40e01cdcea - foreign key (team_id) references teams (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012517_templates.sql b/crates/util/migrations/20231007012517_templates.sql deleted file mode 100644 index 9032c42..0000000 --- a/crates/util/migrations/20231007012517_templates.sql +++ /dev/null @@ -1,24 +0,0 @@ -create table if not exists templates -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - code varchar(255) not null, - name varchar(255) not null, - description varchar(255) null, - usage_count int null, - creator_id numeric(20, 0) null constraint chk_creator_id_range check (creator_id >= 0 AND creator_id <= 18446744073709551615), - created_at timestamp not null, - updated_at timestamp not null, - source_guild_id numeric(20, 0) null constraint chk_source_guild_id_range check (source_guild_id >= 0 AND source_guild_id <= 18446744073709551615), - serialized_source_guild text not null, - constraint IDX_be38737bf339baf63b1daeffb5 - unique (code), - constraint FK_445d00eaaea0e60a017a5ed0c11 - foreign key (source_guild_id) references guilds (id) - on delete cascade, - constraint FK_d7374b7f8f5fbfdececa4fb62e1 - foreign key (creator_id) references users (id) -); - -alter table guilds - add constraint FK_e2a2f873a64a5cf62526de42325 - foreign key (template_id) references templates (id); diff --git a/crates/util/migrations/20231007012542_valid_registration_tokens.sql b/crates/util/migrations/20231007012542_valid_registration_tokens.sql deleted file mode 100644 index ae85bbb..0000000 --- a/crates/util/migrations/20231007012542_valid_registration_tokens.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table if not exists valid_registration_tokens -( - token varchar(255) not null - primary key, - created_at timestamp not null, - expires_at timestamp not null -); \ No newline at end of file diff --git a/crates/util/migrations/20231007012555_voice_states.sql b/crates/util/migrations/20231007012555_voice_states.sql deleted file mode 100644 index 5b6a3a6..0000000 --- a/crates/util/migrations/20231007012555_voice_states.sql +++ /dev/null @@ -1,26 +0,0 @@ -create table if not exists voice_states -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - session_id numeric(20, 0) not null constraint chk_session_id_range check (session_id >= 0 AND session_id <= 18446744073709551615), - token varchar(255) null, - deaf boolean not null, - mute boolean not null, - self_deaf boolean not null, - self_mute boolean not null, - self_stream boolean null, - self_video boolean not null, - suppress boolean not null, - request_to_speak_timestamp timestamp null, - constraint FK_03779ef216d4b0358470d9cb748 - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_5fe1d5f931a67e85039c640001b - foreign key (user_id) references users (id) - on delete cascade, - constraint FK_9f8d389866b40b6657edd026dd4 - foreign key (channel_id) references channels (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012609_webhooks.sql b/crates/util/migrations/20231007012609_webhooks.sql deleted file mode 100644 index 6026c35..0000000 --- a/crates/util/migrations/20231007012609_webhooks.sql +++ /dev/null @@ -1,28 +0,0 @@ -create table if not exists webhooks -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - type int not null, - name varchar(255) null, - avatar varchar(255) null, - token varchar(255) null, - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - application_id numeric(20, 0) null constraint chk_application_id_range check (application_id >= 0 AND application_id <= 18446744073709551615), - user_id numeric(20, 0) null constraint chk_user_id_range check (user_id >= 0 AND user_id <= 18446744073709551615), - source_guild_id numeric(20, 0) null constraint chk_source_guild_id_range check (source_guild_id >= 0 AND source_guild_id <= 18446744073709551615), - constraint FK_0d523f6f997c86e052c49b1455f - foreign key (user_id) references users (id) - on delete cascade, - constraint FK_3a285f4f49c40e0706d3018bc9f - foreign key (source_guild_id) references guilds (id) - on delete cascade, - constraint FK_487a7af59d189f744fe394368fc - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_c3e5305461931763b56aa905f1c - foreign key (application_id) references applications (id) - on delete cascade, - constraint FK_df528cf77e82f8032230e7e37d8 - foreign key (channel_id) references channels (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012620_messages.sql b/crates/util/migrations/20231007012620_messages.sql deleted file mode 100644 index 471284a..0000000 --- a/crates/util/migrations/20231007012620_messages.sql +++ /dev/null @@ -1,46 +0,0 @@ -create table if not exists messages -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - guild_id numeric(20, 0) null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - author_id numeric(20, 0) null constraint chk_author_id_range check (author_id >= 0 AND author_id <= 18446744073709551615), - member_id numeric(20, 0) null constraint chk_member_id_range check (member_id >= 0 AND member_id <= 18446744073709551615), - webhook_id numeric(20, 0) null constraint chk_webhook_id_range check (webhook_id >= 0 AND webhook_id <= 18446744073709551615), - application_id numeric(20, 0) null constraint chk_application_id_range check (application_id >= 0 AND application_id <= 18446744073709551615), - content varchar(255) null, - timestamp timestamp(6) default current_timestamp(6) not null, - edited_timestamp timestamp null, - tts boolean null, - mention_everyone boolean null, - embeds text not null, - reactions text not null, - nonce text null, - pinned boolean null, - type int not null, - activity text null, - flags int null, - message_reference text null, - interaction text null, - components text null, - message_reference_id numeric(20, 0) null constraint chk_message_reference_id_range check (message_reference_id >= 0 AND message_reference_id <= 18446744073709551615), - constraint IDX_3ed7a60fb7dbe04e1ba9332a8b - unique (channel_id, id), - constraint FK_05535bc695e9f7ee104616459d3 - foreign key (author_id) references users (id) - on delete cascade, - constraint FK_5d3ec1cb962de6488637fd779d6 - foreign key (application_id) references applications (id), - constraint FK_61a92bb65b302a76d9c1fcd3174 - foreign key (message_reference_id) references messages (id), - constraint FK_86b9109b155eb70c0a2ca3b4b6d - foreign key (channel_id) references channels (id) - on delete cascade, - constraint FK_b0525304f2262b7014245351c76 - foreign key (member_id) references users (id) - on delete cascade, - constraint FK_b193588441b085352a4c0109423 - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint FK_f83c04bcf1df4e5c0e7a52ed348 - foreign key (webhook_id) references webhooks (id) -); diff --git a/crates/util/migrations/20231007012640_attachments.sql b/crates/util/migrations/20231007012640_attachments.sql deleted file mode 100644 index bd77658..0000000 --- a/crates/util/migrations/20231007012640_attachments.sql +++ /dev/null @@ -1,15 +0,0 @@ -create table if not exists attachments -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - filename varchar(255) not null, - size int not null, - url varchar(255) not null, - proxy_url varchar(255) not null, - height int null, - width int null, - content_type varchar(255) null, - message_id numeric(20, 0) null constraint chk_message_id_range check (message_id >= 0 AND message_id <= 18446744073709551615), - constraint FK_623e10eec51ada466c5038979e3 - foreign key (message_id) references messages (id) - on delete cascade -); diff --git a/crates/util/migrations/20231007012656_message_channel_mentions.sql b/crates/util/migrations/20231007012656_message_channel_mentions.sql deleted file mode 100644 index 105d7e8..0000000 --- a/crates/util/migrations/20231007012656_message_channel_mentions.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table if not exists message_channel_mentions -( - messagesId numeric(20, 0) not null constraint chk_messages_id_range check (messagesId >= 0 AND messagesId <= 18446744073709551615), - channelsId numeric(20, 0) not null constraint chk_channels_id_range check (channelsId >= 0 AND channelsId <= 18446744073709551615), - primary key (messagesId, channelsId), - constraint FK_2a27102ecd1d81b4582a4360921 - foreign key (messagesId) references messages (id) - on update cascade on delete cascade, - constraint FK_bdb8c09e1464cabf62105bf4b9d - foreign key (channelsId) references channels (id) - on update cascade on delete cascade -); - -create index if not exists IDX_2a27102ecd1d81b4582a436092 - on message_channel_mentions (messagesId); - -create index if not exists IDX_bdb8c09e1464cabf62105bf4b9 - on message_channel_mentions (channelsId); diff --git a/crates/util/migrations/20231007012735_message_role_mentions.sql b/crates/util/migrations/20231007012735_message_role_mentions.sql deleted file mode 100644 index 057d45e..0000000 --- a/crates/util/migrations/20231007012735_message_role_mentions.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table if not exists message_role_mentions -( - messagesId numeric(20, 0) not null constraint chk_messages_id_range check (messagesId >= 0 AND messagesId <= 18446744073709551615), - rolesId numeric(20, 0) not null constraint chk_roles_id_range check (rolesId >= 0 AND rolesId <= 18446744073709551615), - primary key (messagesId, rolesId), - constraint FK_29d63eb1a458200851bc37d074b - foreign key (rolesId) references roles (id) - on update cascade on delete cascade, - constraint FK_a8242cf535337a490b0feaea0b4 - foreign key (messagesId) references messages (id) - on update cascade on delete cascade -); - -create index if not exists IDX_29d63eb1a458200851bc37d074 - on message_role_mentions (rolesId); - -create index if not exists IDX_a8242cf535337a490b0feaea0b - on message_role_mentions (messagesId); diff --git a/crates/util/migrations/20231007012751_message_stickers.sql b/crates/util/migrations/20231007012751_message_stickers.sql deleted file mode 100644 index 9b4ee73..0000000 --- a/crates/util/migrations/20231007012751_message_stickers.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table if not exists message_stickers -( - messagesId numeric(20, 0) not null constraint chk_messages_id_range check (messagesId >= 0 AND messagesId <= 18446744073709551615), - stickersId numeric(20, 0) not null constraint chk_stickers_id_range check (stickersId >= 0 AND stickersId <= 18446744073709551615), - primary key (messagesId, stickersId), - constraint FK_40bb6f23e7cc133292e92829d28 - foreign key (messagesId) references messages (id) - on update cascade on delete cascade, - constraint FK_e22a70819d07659c7a71c112a1f - foreign key (stickersId) references stickers (id) - on update cascade on delete cascade -); - -create index if not exists IDX_40bb6f23e7cc133292e92829d2 - on message_stickers (messagesId); - -create index if not exists IDX_e22a70819d07659c7a71c112a1 - on message_stickers (stickersId); diff --git a/crates/util/migrations/20231007012803_message_user_mentions.sql b/crates/util/migrations/20231007012803_message_user_mentions.sql deleted file mode 100644 index 99c7e78..0000000 --- a/crates/util/migrations/20231007012803_message_user_mentions.sql +++ /dev/null @@ -1,24 +0,0 @@ -create table if not exists message_user_mentions -( - messagesId numeric(20, 0) not null constraint chk_messages_id_range check (messagesId >= 0 AND messagesId <= 18446744073709551615), - usersId numeric(20, 0) not null constraint chk_users_id_range check (usersId >= 0 AND usersId <= 18446744073709551615), - primary key (messagesId, usersId), - constraint FK_a343387fc560ef378760681c236 - foreign key (messagesId) references messages (id) - on update cascade on delete cascade, - constraint FK_b831eb18ceebd28976239b1e2f8 - foreign key (usersId) references users (id) - on update cascade on delete cascade -); - -create index if not exists IDX_a343387fc560ef378760681c23 - on message_user_mentions (messagesId); - -create index if not exists IDX_b831eb18ceebd28976239b1e2f - on message_user_mentions (usersId); - -create index if not exists IDX_05535bc695e9f7ee104616459d - on messages (author_id); - -create index if not exists IDX_86b9109b155eb70c0a2ca3b4b6 - on messages (channel_id); diff --git a/crates/util/migrations/20240605191045_guild_scheduled_events.sql b/crates/util/migrations/20240605191045_guild_scheduled_events.sql deleted file mode 100644 index 4f06268..0000000 --- a/crates/util/migrations/20240605191045_guild_scheduled_events.sql +++ /dev/null @@ -1,37 +0,0 @@ -create table if not exists guild_scheduled_events -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - creator_id numeric(20, 0) null constraint chk_creator_id_range check (creator_id >= 0 AND creator_id <= 18446744073709551615), - name varchar(100) null, - description text null, - scheduled_start_time timestamp default CURRENT_TIMESTAMP not null, - scheduled_end_time timestamp null, - privacy_level int not null, - status int not null, - entity_type int not null, - entity_id numeric(20, 0) null constraint chk_entity_id_range check (entity_id >= 0 AND entity_id <= 18446744073709551615), - location varchar(100) null, - user_count int default 0 not null, - image text null, - constraint guild_scheduled_event_channels_id_fk - foreign key (channel_id) references channels (id), - constraint guild_scheduled_event_guilds_id_fk - foreign key (guild_id) references guilds (id), - constraint guild_scheduled_event_users_id_fk - foreign key (creator_id) references users (id) -); - -create or replace function update_scheduled_start_time() -returns TRIGGER as $$ -begin - NEW.scheduled_start_time := CURRENT_TIMESTAMP; - return NEW; -end; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER update_scheduled_start_time_trigger -BEFORE UPDATE ON guild_scheduled_events -FOR EACH ROW -EXECUTE FUNCTION update_scheduled_start_time(); diff --git a/crates/util/migrations/20240605192122_stage_instances.sql b/crates/util/migrations/20240605192122_stage_instances.sql deleted file mode 100644 index 549da35..0000000 --- a/crates/util/migrations/20240605192122_stage_instances.sql +++ /dev/null @@ -1,19 +0,0 @@ -create table if not exists stage_instances -( - id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key, - guild_id numeric(20, 0) not null constraint chk_guild_id_range check (guild_id >= 0 AND guild_id <= 18446744073709551615), - channel_id numeric(20, 0) not null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - topic varchar(120) not null, - privacy_level int not null, - invite_code varchar(16) null, - discoverable_disabled boolean not null default false, - guild_scheduled_event_id numeric(20, 0) null constraint chk_guild_scheduled_event_id_range check (guild_scheduled_event_id >= 0 AND guild_scheduled_event_id <= 18446744073709551615), - constraint stage_instances_channels_id_fk - foreign key (channel_id) references channels (id) - on delete cascade, - constraint stage_instances_guilds_id_fk - foreign key (guild_id) references guilds (id) - on delete cascade, - constraint stage_instances_guild_scheduled_events_id_fk - foreign key (guild_scheduled_event_id) references guild_scheduled_events (id) -); diff --git a/crates/util/migrations/20240607211359_read_states_add_message_fk.sql b/crates/util/migrations/20240607211359_read_states_add_message_fk.sql deleted file mode 100644 index ef5906c..0000000 --- a/crates/util/migrations/20240607211359_read_states_add_message_fk.sql +++ /dev/null @@ -1,8 +0,0 @@ -alter table read_states - add constraint read_states_messages_id_fk - foreign key (last_message_id) references messages (id) - on delete cascade; -alter table read_states - add constraint read_states_users_id_fk_2 - foreign key (notifications_cursor) references messages (id) - on delete cascade; diff --git a/crates/util/migrations/20240619142920_channel_followers.sql b/crates/util/migrations/20240619142920_channel_followers.sql deleted file mode 100644 index 0a48f20..0000000 --- a/crates/util/migrations/20240619142920_channel_followers.sql +++ /dev/null @@ -1,12 +0,0 @@ -create table channel_followers -( - webhook_id numeric(20, 0) not null constraint chk_webhook_id_range check (webhook_id >= 0 AND webhook_id <= 18446744073709551615), - channel_id numeric(20, 0) not null constraint chk_channel_id_range check (channel_id >= 0 AND channel_id <= 18446744073709551615), - primary key (channel_id, webhook_id), - constraint channel_followers_channels_id_fk - foreign key (channel_id) references channels (id) - on delete cascade, - constraint channel_followers_webhooks_id_fk - foreign key (webhook_id) references webhooks (id) - on delete cascade -); diff --git a/crates/util/src/gateway/mod.rs b/crates/util/src/gateway/mod.rs index 30a84f4..20f7b2d 100644 --- a/crates/util/src/gateway/mod.rs +++ b/crates/util/src/gateway/mod.rs @@ -2,6 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// TODO: symfonia-gateway should include a `lib` target. Files in this directory +// should then be moved there. + use std::{ collections::{HashMap, HashSet}, fmt::Display, diff --git a/file-renamer.sh b/file-renamer.sh new file mode 100755 index 0000000..00fcaaf --- /dev/null +++ b/file-renamer.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Check if correct number of arguments provided +if [ $# -ne 2 ]; then + echo "Usage: $0 " + echo "Example: $0 00005 2" + exit 1 +fi + +start_num="$1" +add_num="$2" +directory="crates/util/migrations" + +# Convert start_num to integer for comparison +start_int=$(echo "$start_num" | sed 's/^0*//') +start_int=${start_int:-0} # Handle case where start_num is all zeros + +# Check if directory exists +if [ ! -d "$directory" ]; then + echo "Directory $directory does not exist" + exit 1 +fi + +# Find files matching pattern and filter by number >= start_num +files_to_rename=() +while IFS= read -r -d '' file; do + filename=$(basename "$file") + if [[ $filename =~ ^([0-9]{5})_(.+)\.sql$ ]]; then + file_num="${BASH_REMATCH[1]}" + file_int=$(echo "$file_num" | sed 's/^0*//') + file_int=${file_int:-0} + + if [ "$file_int" -ge "$start_int" ]; then + files_to_rename+=("$filename:$file_int") + fi + fi +done < <(find "$directory" -maxdepth 1 -name "*.sql" -print0) + +# Sort files by number (descending to avoid conflicts during renaming) +IFS=$'\n' sorted_files=($(printf '%s\n' "${files_to_rename[@]}" | sort -t: -k2 -nr)) + +# Rename files +for entry in "${sorted_files[@]}"; do + filename="${entry%:*}" + file_num="${entry#*:}" + + new_num=$((file_num + add_num)) + new_filename=$(printf "%05d_%s" "$new_num" "${filename:6}") + + old_path="$directory/$filename" + new_path="$directory/$new_filename" + + echo "Renaming $old_path to $new_path" + git mv "$old_path" "$new_path" +done + +echo "Done!"