Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.9 KB
Raw Blame
-- This fixture creates three documents with deliberately different timestamps for
-- `createdAt`, `updatedAt` (on the item), and `updatedAt` (in UserHistory)
-- to allow for testing all three sorting methods independently.

-- Expected Order for CreatedAt:   doc-B, doc-C, doc-A
-- Expected Order for UpdatedAt:   doc-C, doc-A, doc-B
-- Expected Order for LastViewed:  doc-A, doc-B, doc-C

-- Disable foreign key constraints temporarily
SET session_replication_role = 'replica';

INSERT INTO public."macro_user" ("id", "username", "email", "stripe_customer_id")
VALUES ('a1111111-1111-1111-1111-111111111111', '[email protected]', '[email protected]', 'stripe_id');

INSERT INTO public."User" ("id", "email", "stripeCustomerId", "macro_user_id")
VALUES ('macro|[email protected]', '[email protected]', 'stripe_id', 'a1111111-1111-1111-1111-111111111111');

-- Document A: Oldest created, middle updated, newest viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc A', 'txt', 'macro|[email protected]', '2024-01-01 10:00:00', '2024-01-02 11:00:00');

-- Document B: Newest created, oldest updated, middle viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
VALUES ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Doc B', 'pdf', 'macro|[email protected]', '2024-01-01 12:00:00', '2024-01-02 10:00:00');

-- Document C: Middle created, newest updated, oldest viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
VALUES ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'Doc C', 'pdf', 'macro|[email protected]', '2024-01-01 11:00:00', '2024-01-02 12:00:00');

-- Instances (needed for the query to run)
INSERT INTO public."DocumentInstance" ("documentId", "sha")
VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-a'),
       ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'sha-b'),
       ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'sha-c');

-- Give the user access to all three documents
INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner'),
       ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'owner'),
       ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'document', 'macro|[email protected]', 'user', 'owner');

-- Create UserHistory entries with their own distinct ordering
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
VALUES ('macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', '2024-01-03 12:00:00'), -- Newest viewed
       ('macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', '2024-01-03 11:00:00');
-- Doc C has no user_history entry
-- Oldest viewed

-- Re-enable foreign key constraints
SET session_replication_role = 'origin';