create_tracking_table.sql 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- =============================================================================
  2. -- Embase Conference Abstract Scheduler — Tracking Table
  3. -- =============================================================================
  4. -- Run this script once on the target PostgreSQL database before the first
  5. -- scheduler execution.
  6. -- =============================================================================
  7. -- ---------------------------------------------------------------------------
  8. -- 1. Tracking table
  9. -- ---------------------------------------------------------------------------
  10. CREATE TABLE IF NOT EXISTS tblEmbaseConferenceDispatch
  11. (
  12. Id BIGSERIAL PRIMARY KEY,
  13. SourceId BIGINT NOT NULL,
  14. LotId BIGINT NOT NULL,
  15. FileName VARCHAR(200) NOT NULL,
  16. DispatchDate TIMESTAMP NOT NULL,
  17. CreatedOn TIMESTAMP NOT NULL DEFAULT NOW()
  18. );
  19. COMMENT ON TABLE tblEmbaseConferenceDispatch IS 'Tracks conference abstract lots that have already been packaged and uploaded to SFTP.';
  20. COMMENT ON COLUMN tblEmbaseConferenceDispatch.SourceId IS 'Journal / source identifier (maps to tblsrmaster.sourceid).';
  21. COMMENT ON COLUMN tblEmbaseConferenceDispatch.LotId IS 'Lot that was included in the dispatched ZIP.';
  22. COMMENT ON COLUMN tblEmbaseConferenceDispatch.FileName IS 'Name of the generated ZIP file (e.g. emconflum0000007.zip).';
  23. COMMENT ON COLUMN tblEmbaseConferenceDispatch.DispatchDate IS 'UTC timestamp when the ZIP was successfully uploaded.';
  24. COMMENT ON COLUMN tblEmbaseConferenceDispatch.CreatedOn IS 'Row insertion timestamp.';
  25. -- ---------------------------------------------------------------------------
  26. -- 2. Indexes for common access patterns
  27. -- ---------------------------------------------------------------------------
  28. -- Used by the "NOT IN dispatch" exclusion sub-query
  29. CREATE INDEX IF NOT EXISTS idx_embase_conf_dispatch_lotid
  30. ON tblEmbaseConferenceDispatch (LotId);
  31. -- Used when auditing dispatches for a given source
  32. CREATE INDEX IF NOT EXISTS idx_embase_conf_dispatch_sourceid
  33. ON tblEmbaseConferenceDispatch (SourceId);
  34. -- Unique constraint: a lot should only be dispatched once
  35. ALTER TABLE tblEmbaseConferenceDispatch
  36. ADD CONSTRAINT uq_embase_conf_dispatch_lot UNIQUE (LotId);
  37. -- ---------------------------------------------------------------------------
  38. -- 3. Verification query — run after creation to confirm structure
  39. -- ---------------------------------------------------------------------------
  40. -- SELECT column_name, data_type, column_default
  41. -- FROM information_schema.columns
  42. -- WHERE table_name = 'tblembaseconferencedispatch'
  43. -- ORDER BY ordinal_position;