2_create_subscriptions.up.sql 865 B

1234567891011121314151617181920212223242526272829
  1. CREATE TABLE IF NOT EXISTS subscriptions (
  2. subscription_id SERIAL PRIMARY KEY,
  3. user_id INTEGER NOT NULL,
  4. storage_in_mbs BIGINT NOT NULL,
  5. original_transaction_id TEXT NOT NULL,
  6. expiry_time BIGINT NOT NULL,
  7. created_at TIMESTAMP NOT NULL DEFAULT NOW(),
  8. CONSTRAINT fk_subscriptions_user_id
  9. FOREIGN KEY(user_id)
  10. REFERENCES users(user_id)
  11. ON DELETE CASCADE
  12. );
  13. CREATE TABLE IF NOT EXISTS subscription_logs (
  14. log_id SERIAL PRIMARY KEY,
  15. user_id INTEGER NOT NULL,
  16. payment_provider TEXT NOT NULL,
  17. notification JSONB NOT NULL,
  18. verification_response JSONB NOT NULL,
  19. created_at TIMESTAMP NOT NULL DEFAULT NOW(),
  20. CONSTRAINT fk_subscription_logs_user_id
  21. FOREIGN KEY(user_id)
  22. REFERENCES users(user_id)
  23. ON DELETE CASCADE
  24. );
  25. CREATE INDEX IF NOT EXISTS subscriptions_user_id_index ON subscriptions(user_id);