diff --git a/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/down.cql b/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/down.cql index 5e161a2b4e..f8019cd31b 100644 --- a/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/down.cql +++ b/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/down.cql @@ -1,3 +1,5 @@ +DROP MATERIALIZED VIEW IF EXISTS reaction_by_user_id; +DROP MATERIALIZED VIEW IF EXISTS reaction_by_id; CREATE TYPE IF NOT EXISTS emoji ( "name" text, "url" text, @@ -5,3 +7,16 @@ CREATE TYPE IF NOT EXISTS emoji ( "height" int, ); ALTER TABLE reaction ADD "emoji" frozen; +CREATE MATERIALIZED VIEW IF NOT EXISTS reaction_by_user_id AS + SELECT * FROM reaction + WHERE "userId" IS NOT NULL + AND "createdAt" IS NOT NULL + AND "noteId" IS NOT NULL + PRIMARY KEY ("userId", "createdAt", "noteId") + WITH CLUSTERING ORDER BY ("createdAt" DESC); +CREATE MATERIALIZED VIEW IF NOT EXISTS reaction_by_id AS + SELECT * FROM reaction + WHERE "noteId" IS NOT NULL + AND "reaction" IS NOT NULL + AND "userId" IS NOT NULL + PRIMARY KEY ("noteId", "reaction", "userId"); diff --git a/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/up.cql b/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/up.cql index 8a8700d6ea..4bfd993265 100644 --- a/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/up.cql +++ b/packages/backend/native-utils/scylla-migration/cql/1694224890248_drop_emoji_type/up.cql @@ -1,2 +1,17 @@ +DROP MATERIALIZED VIEW reaction_by_user_id; +DROP MATERIALIZED VIEW reaction_by_id; ALTER TABLE reaction DROP "emoji"; DROP TYPE emoji; +CREATE MATERIALIZED VIEW reaction_by_user_id AS + SELECT * FROM reaction + WHERE "userId" IS NOT NULL + AND "createdAt" IS NOT NULL + AND "noteId" IS NOT NULL + PRIMARY KEY ("userId", "createdAt", "noteId") + WITH CLUSTERING ORDER BY ("createdAt" DESC); +CREATE MATERIALIZED VIEW reaction_by_id AS + SELECT * FROM reaction + WHERE "noteId" IS NOT NULL + AND "reaction" IS NOT NULL + AND "userId" IS NOT NULL + PRIMARY KEY ("noteId", "reaction", "userId");