mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-05-31 15:44:30 +00:00
fix: add CHECK constraint on file_size > 0
Prevents negative or zero file_size values at the database level. Without this, corrupted data from import or direct DB access could cause incorrect storage accounting (getUsedStorage sums file_size, and expiredFiles casts to Word32 which wraps negative values).
This commit is contained in:
@@ -14,7 +14,8 @@ import Text.RawString.QQ (r)
|
||||
|
||||
xftpSchemaMigrations :: [(String, Text, Maybe Text)]
|
||||
xftpSchemaMigrations =
|
||||
[ ("20260325_initial", m20260325_initial, Nothing)
|
||||
[ ("20260325_initial", m20260325_initial, Nothing),
|
||||
("20260402_file_size_check", m20260402_file_size_check, Just down_m20260402_file_size_check)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
@@ -45,3 +46,15 @@ CREATE TABLE recipients (
|
||||
CREATE INDEX idx_recipients_sender_id ON recipients (sender_id);
|
||||
CREATE INDEX idx_files_created_at ON files (created_at);
|
||||
|]
|
||||
|
||||
m20260402_file_size_check :: Text
|
||||
m20260402_file_size_check =
|
||||
[r|
|
||||
ALTER TABLE files ADD CONSTRAINT check_file_size_positive CHECK (file_size > 0);
|
||||
|]
|
||||
|
||||
down_m20260402_file_size_check :: Text
|
||||
down_m20260402_file_size_check =
|
||||
[r|
|
||||
ALTER TABLE files DROP CONSTRAINT check_file_size_positive;
|
||||
|]
|
||||
|
||||
Reference in New Issue
Block a user