Skip to content

Commit

Permalink
Merge pull request #39 from polyphony-chat/sqlx-updates
Browse files Browse the repository at this point in the history
Migration to PostgreSQL and sqlx version upgrade
  • Loading branch information
bitfl0wer authored Aug 22, 2024
2 parents 909e29a + 830a05c commit 292c1cd
Show file tree
Hide file tree
Showing 100 changed files with 803 additions and 805 deletions.
2 changes: 1 addition & 1 deletion .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[hooks]
pre-push = "cargo fmt --all -- --check --color always"
pre-push = "cargo fmt -- --check --color always"

[logging]
verbose = true
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ regex = "1.10.4"
reqwest = "0.12.4"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = { version = "1.0.117", features = ["raw_value"] }
sqlx = { version = "0.7.4", features = [
sqlx = { version = "0.8.0", features = [
"json",
"chrono",
"ipnetwork",
Expand All @@ -46,14 +46,13 @@ thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["full"] }
sentry = "0.33.0"
clap = { version = "4.5.4", features = ["derive"] }

chorus = { git = "http://github.com/polyphony-chat/chorus", rev = "537b025", features = [
chorus = { features = [
"backend",
], default-features = false } # git = "ssh://[email protected]/Quat3rnion/chorus" # path = "../chorus" git = "ssh://[email protected]/polyphony-chat/chorus"
], default-features = false, git = "https://github.com/polyphony-chat/chorus", branch = "dev" } # git = "ssh://[email protected]/Quat3rnion/chorus" # path = "../chorus" git = "ssh://[email protected]/polyphony-chat/chorus"
serde_path_to_error = "0.1.16"
percent-encoding = "2.3.1"
hex = "0.4.3"
itertools = "0.13.0"

sqlx-pg-uint = { version = "0.4.1", features = ["serde"] }
[dev-dependencies]
rusty-hook = "0.11.2"
6 changes: 3 additions & 3 deletions compose-example.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MARIADB_USER=symfonia
MARIADB_PASSWORD=symfonia
MARIADB_DATABASE=symfonia
POSTGRES_USER=symfonia
POSTGRES_PASSWORD=symfonia
POSTGRES_DB=symfonia
31 changes: 12 additions & 19 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
services:
db:
env_file: .env
image: mariadb
environment:
MARIADB_RANDOM_ROOT_PASSWORD: 1
image: postgres
volumes:
- "mariadb:/var/lib/mysql"
- "postgres:/var/lib/postgresql/data"
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
healthcheck:
test:
[
"CMD",
"healthcheck.sh",
"--connect",
"--innodb_initialized"
]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3
test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}"]
interval: 3s
timeout: 3s
retries: 10
app:
env_file: .env
build: .
environment:
- DATABASE_URL=db
- DATABASE_USERNAME=${MARIADB_USER}
- DATABASE_PASSWORD=${MARIADB_PASSWORD}
- DATABASE_NAME=${MARIADB_DATABASE}
- DATABASE_USERNAME=${POSTGRES_USER}
- DATABASE_PASSWORD=${POSTGRES_PASSWORD}
- DATABASE_NAME=${POSTGRES_DB}
depends_on:
db:
condition: service_healthy
Expand All @@ -36,4 +29,4 @@ services:
- 3003:3003/udp

volumes:
mariadb:
postgres:
2 changes: 1 addition & 1 deletion migrations/20231007011602_categories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ create table if not exists categories
primary key,
name varchar(255) null,
localizations text not null,
is_primary tinyint null
is_primary smallint null
);
4 changes: 2 additions & 2 deletions migrations/20231007011617_client_release.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ create table if not exists client_release
id varchar(255) not null
primary key,
name varchar(255) not null,
pub_date datetime not null,
pub_date timestamp not null,
url varchar(255) not null,
platform varchar(255) not null,
enabled tinyint not null,
enabled smallint not null,
notes varchar(255) null
);
4 changes: 2 additions & 2 deletions migrations/20231007011631_config.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create table if not exists config
(
`key` varchar(255) not null
key varchar(255) not null
primary key,
value text null
value json null
);
2 changes: 1 addition & 1 deletion migrations/20231007011653_connection_config.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create table if not exists connection_config
(
`key` varchar(255) not null
key varchar(255) not null
primary key,
value text null
);
4 changes: 2 additions & 2 deletions migrations/20231007011719_rate_limits.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ create table if not exists rate_limits
primary key,
executor_id varchar(255) not null,
hits int not null,
blocked tinyint not null,
expires_at datetime not null
blocked smallint not null,
expires_at timestamp not null
);
69 changes: 35 additions & 34 deletions migrations/20231007011756_user_settings.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
create table if not exists user_settings
CREATE SEQUENCE user_settings_index_seq;

CREATE TABLE IF NOT EXISTS user_settings
(
`index` bigint unsigned auto_increment
primary key,
afk_timeout int null,
allow_accessibility_detection tinyint null,
animate_emoji tinyint null,
animate_stickers int null,
contact_sync_enabled tinyint null,
convert_emoticons tinyint null,
custom_status text null,
default_guilds_restricted tinyint null,
detect_platform_accounts tinyint null,
developer_mode tinyint null,
disable_games_tab tinyint null,
enable_tts_command tinyint null,
explicit_content_filter int null,
friend_source_flags text null,
gateway_connected tinyint null,
gif_auto_play tinyint null,
guild_folders text null,
guild_positions text null,
inline_attachment_media tinyint null,
inline_embed_media tinyint null,
locale varchar(255) null,
message_display_compact tinyint null,
native_phone_integration_enabled tinyint null,
render_embeds tinyint null,
render_reactions tinyint null,
restricted_guilds text null,
show_current_game tinyint null,
status varchar(255) null,
stream_notifications_enabled tinyint null,
theme varchar(255) null,
timezone_offset int null
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 smallint null,
animate_emoji smallint null,
animate_stickers int null,
contact_sync_enabled smallint null,
convert_emoticons smallint null,
custom_status text null,
default_guilds_restricted smallint null,
detect_platform_accounts smallint null,
developer_mode smallint null,
disable_games_tab smallint null,
enable_tts_command smallint null,
explicit_content_filter int null,
friend_source_flags text null,
gateway_connected smallint null,
gif_auto_play smallint null,
guild_folders text null,
guild_positions text null,
inline_attachment_media smallint null,
inline_embed_media smallint null,
locale varchar(255) null,
message_display_compact smallint null,
native_phone_integration_enabled smallint null,
render_embeds smallint null,
render_reactions smallint null,
restricted_guilds text null,
show_current_game smallint null,
status varchar(255) null,
stream_notifications_enabled smallint null,
theme varchar(255) null,
timezone_offset int null
);

74 changes: 37 additions & 37 deletions migrations/20231007011757_users.sql
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
create table if not exists users
(
id varchar(255) not null
id varchar(255) not null
primary key,
username varchar(255) not null,
discriminator varchar(255) not null,
avatar varchar(255) null,
accent_color int null,
banner varchar(255) null,
theme_colors text null,
pronouns varchar(255) null,
phone varchar(255) null,
desktop tinyint not null,
mobile tinyint not null,
premium tinyint not null,
premium_type tinyint unsigned not null,
bot tinyint not null,
bio varchar(255) not null,
`system` tinyint not null,
nsfw_allowed tinyint not null,
mfa_enabled tinyint not null,
webauthn_enabled tinyint default 0 not null,
totp_secret varchar(255) null,
totp_last_ticket varchar(255) null,
created_at datetime not null,
premium_since datetime null,
verified tinyint not null,
disabled tinyint not null,
deleted tinyint not null,
email varchar(255) null,
flags bigint unsigned not null,
public_flags int unsigned not null,
purchased_flags int not null,
premium_usage_flags int not null,
rights bigint not null,
data text not null,
fingerprints text not null,
extended_settings text not null,
settingsIndex bigint unsigned null,
username varchar(255) not null,
discriminator varchar(255) not null,
avatar varchar(255) null,
accent_color int null,
banner varchar(255) null,
theme_colors text null,
pronouns varchar(255) null,
phone varchar(255) null,
desktop smallint not null,
mobile smallint not null,
premium smallint not null,
premium_type numeric(5, 0) not null constraint chk_smallint_unsigned check (premium_type >= 0 and premium_type <= 65535),
bot smallint not null,
bio varchar(255) not null,
system smallint not null,
nsfw_allowed smallint not null,
mfa_enabled smallint not null,
webauthn_enabled smallint default 0 not null,
totp_secret varchar(255) null,
totp_last_ticket varchar(255) null,
created_at timestamp not null,
premium_since timestamp null,
verified smallint not null,
disabled smallint not null,
deleted smallint not null,
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 bigint not null,
data text not null,
fingerprints text not null,
extended_settings text not null,
settingsIndex numeric(20, 0) null constraint chk_settingsIndex_range check (settingsIndex >= 0 AND settingsIndex <= 18446744073709551615),
constraint users_settingsIndex_uindex
unique (settingsIndex),
constraint users_user_settings_index_fk
foreign key (settingsIndex) references user_settings (`index`)
foreign key (settingsIndex) references user_settings (index)
);

4 changes: 2 additions & 2 deletions migrations/20231007011910_backup_codes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ create table if not exists backup_codes
id varchar(255) not null
primary key,
code varchar(255) not null,
consumed tinyint not null,
expired tinyint not null,
consumed smallint not null,
expired smallint not null,
user_id varchar(255) null,
constraint FK_70066ea80d2f4b871beda32633b
foreign key (user_id) references users (id)
Expand Down
4 changes: 2 additions & 2 deletions migrations/20231007011933_channels.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ create table if not exists channels
(
id varchar(255) not null
primary key,
created_at datetime not null,
created_at timestamp not null,
name varchar(255) null,
icon text null,
type int not null,
Expand All @@ -17,7 +17,7 @@ create table if not exists channels
video_quality_mode int null,
bitrate int null,
user_limit int null,
nsfw tinyint not null,
nsfw smallint not null,
rate_limit_per_user int null,
topic varchar(255) null,
retention_policy_id varchar(255) null,
Expand Down
8 changes: 4 additions & 4 deletions migrations/20231007011946_connected_accounts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ create table if not exists connected_accounts
primary key,
external_id varchar(255) not null,
user_id varchar(255) null,
friend_sync tinyint not null,
friend_sync smallint not null,
name varchar(255) not null,
revoked tinyint not null,
revoked smallint not null,
show_activity int not null,
type varchar(255) not null,
verified tinyint not null,
verified smallint not null,
visibility int not null,
integrations text not null,
metadata text null,
metadata_visibility int not null,
two_way_link tinyint not null,
two_way_link smallint not null,
token_data text null,
constraint FK_f47244225a6a1eac04a3463dd90
foreign key (user_id) references users (id)
Expand Down
10 changes: 5 additions & 5 deletions migrations/20231007011956_guilds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ create table if not exists guilds
features text not null,
primary_category_id varchar(255) null,
icon varchar(255) null,
large tinyint not null,
large smallint not null,
max_members int null,
max_presences int null,
max_video_channel_users int null,
Expand All @@ -31,15 +31,15 @@ create table if not exists guilds
splash varchar(255) null,
system_channel_id varchar(255) null,
system_channel_flags int null,
unavailable tinyint not null,
unavailable smallint not null,
verification_level int null,
welcome_screen text not null,
widget_channel_id varchar(255) null,
widget_enabled tinyint not null,
widget_enabled smallint not null,
nsfw_level int null,
nsfw tinyint not null,
nsfw smallint not null,
parent varchar(255) null,
premium_progress_bar_enabled tinyint null,
premium_progress_bar_enabled smallint null,
constraint FK_8d450b016dc8bec35f36729e4b0
foreign key (public_updates_channel_id) references channels (id),
constraint FK_95828668aa333460582e0ca6396
Expand Down
10 changes: 5 additions & 5 deletions migrations/20231007012108_emojis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ create table if not exists emojis
(
id varchar(255) not null
primary key,
animated tinyint not null,
available tinyint not null,
animated smallint not null,
available smallint not null,
guild_id varchar(255) not null,
user_id varchar(255) null,
managed tinyint not null,
managed smallint not null,
name varchar(255) not null,
require_colons tinyint not null,
require_colons smallint not null,
roles text not null,
`groups` text null,
groups text null,
constraint FK_4b988e0db89d94cebcf07f598cc
foreign key (guild_id) references guilds (id)
on delete cascade,
Expand Down
Loading

0 comments on commit 292c1cd

Please sign in to comment.