mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-04 01:41:43 +00:00
core: use strict tables (#6535)
* core: use strict tables * fix field types * change encodings to match schema types; migrate sqlite tables to strict mode * stabilize postgres client tests, remove slow handshake tests * update simplexmq * fix test * change call_state type to text * fix directory service queries * update local_alias for existing schemas * change types before strict
This commit is contained in:
@@ -23,6 +23,7 @@ import Simplex.Chat.Store.Postgres.Migrations.M20251007_connections_sync
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251017_chat_tags_cascade
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251117_member_relations_vector
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251128_migrate_member_relations
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20251230_strict_tables
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Text, Maybe Text)]
|
||||
@@ -45,7 +46,8 @@ schemaMigrations =
|
||||
("20251007_connections_sync", m20251007_connections_sync, Just down_m20251007_connections_sync),
|
||||
("20251017_chat_tags_cascade", m20251017_chat_tags_cascade, Just down_m20251017_chat_tags_cascade),
|
||||
("20251117_member_relations_vector", m20251117_member_relations_vector, Just down_m20251117_member_relations_vector),
|
||||
("20251128_migrate_member_relations", m20251128_migrate_member_relations, Just down_m20251128_migrate_member_relations)
|
||||
("20251128_migrate_member_relations", m20251128_migrate_member_relations, Just down_m20251128_migrate_member_relations),
|
||||
("20251230_strict_tables", m20251230_strict_tables, Just down_m20251230_strict_tables)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20251230_strict_tables where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Text.RawString.QQ (r)
|
||||
import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20251230_strict_tables (isValidText)
|
||||
|
||||
m20251230_strict_tables :: Text
|
||||
m20251230_strict_tables =
|
||||
isValidText
|
||||
<> [r|
|
||||
DELETE FROM calls
|
||||
WHERE NOT simplex_is_valid_text(call_state);
|
||||
|
||||
ALTER TABLE calls ALTER COLUMN call_state TYPE TEXT USING call_state::TEXT;
|
||||
|
||||
DROP FUNCTION simplex_is_valid_text(BYTEA);
|
||||
|]
|
||||
|
||||
down_m20251230_strict_tables :: Text
|
||||
down_m20251230_strict_tables =
|
||||
[r|
|
||||
ALTER TABLE calls ALTER COLUMN call_state TYPE BYTEA USING call_state::BYTEA;
|
||||
|]
|
||||
@@ -173,7 +173,7 @@ CREATE TABLE test_chat_schema.calls (
|
||||
contact_id bigint NOT NULL,
|
||||
shared_call_id bytea NOT NULL,
|
||||
chat_item_id bigint NOT NULL,
|
||||
call_state bytea NOT NULL,
|
||||
call_state text NOT NULL,
|
||||
call_ts timestamp with time zone NOT NULL,
|
||||
user_id bigint NOT NULL,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user