You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

  1. -- +migrate Up
  2. CREATE TABLE block (
  3. eth_block_num BIGINT PRIMARY KEY,
  4. timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  5. hash BYTEA NOT NULL
  6. );
  7. CREATE TABLE slot_min_prices (
  8. eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
  9. min_prices VARCHAR(200) NOT NULL
  10. );
  11. CREATE TABLE coordianator (
  12. forger_addr BYTEA NOT NULL,
  13. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  14. beneficiary_addr BYTEA NOT NULL,
  15. withdraw_addr BYTEA NOT NULL,
  16. url VARCHAR(200) NOT NULL,
  17. PRIMARY KEY (forger_addr, eth_block_num)
  18. );
  19. CREATE TABLE batch (
  20. batch_num BIGINT PRIMARY KEY,
  21. eth_block_num BIGINT REFERENCES block (eth_block_num) ON DELETE CASCADE,
  22. forger_addr BYTEA NOT NULL, -- fake foreign key for coordinator
  23. fees_collected BYTEA NOT NULL,
  24. state_root BYTEA NOT NULL,
  25. num_accounts BIGINT NOT NULL,
  26. exit_root BYTEA NOT NULL,
  27. forge_l1_txs_num BIGINT,
  28. slot_num BIGINT NOT NULL
  29. );
  30. CREATE TABLE exit_tree (
  31. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  32. account_idx BIGINT NOT NULL,
  33. merkle_proof BYTEA NOT NULL,
  34. amount NUMERIC NOT NULL,
  35. nullifier BYTEA NOT NULL,
  36. PRIMARY KEY (batch_num, account_idx)
  37. );
  38. CREATE TABLE bid (
  39. slot_num BIGINT NOT NULL,
  40. bid_value BYTEA NOT NULL, -- (check if we can do a max(), if not add float for order purposes)
  41. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  42. forger_addr BYTEA NOT NULL, -- fake foreign key for coordinator
  43. PRIMARY KEY (slot_num, bid_value)
  44. );
  45. CREATE TABLE token (
  46. token_id INT PRIMARY KEY,
  47. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  48. eth_addr BYTEA UNIQUE NOT NULL,
  49. name VARCHAR(20) NOT NULL,
  50. symbol VARCHAR(10) NOT NULL,
  51. decimals INT NOT NULL
  52. );
  53. CREATE TABLE l1tx (
  54. tx_id BYTEA PRIMARY KEY,
  55. to_forge_l1_txs_num BIGINT NOT NULL,
  56. position INT NOT NULL,
  57. user_origin BOOLEAN NOT NULL,
  58. from_idx BIGINT NOT NULL,
  59. from_eth_addr BYTEA NOT NULL,
  60. from_bjj BYTEA NOT NULL,
  61. to_idx BIGINT NOT NULL,
  62. token_id INT NOT NULL REFERENCES token (token_id),
  63. amount NUMERIC NOT NULL,
  64. load_amount BYTEA NOT NULL,
  65. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE
  66. );
  67. CREATE TABLE l2tx (
  68. tx_id BYTEA PRIMARY KEY,
  69. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  70. position INT NOT NULL,
  71. from_idx BIGINT NOT NULL,
  72. to_idx BIGINT NOT NULL,
  73. amount NUMERIC NOT NULL,
  74. fee INT NOT NULL,
  75. nonce BIGINT NOT NULL
  76. );
  77. CREATE TABLE account (
  78. idx BIGINT PRIMARY KEY,
  79. token_id INT NOT NULL REFERENCES token (token_id),
  80. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  81. bjj BYTEA NOT NULL,
  82. eth_addr BYTEA NOT NULL
  83. );
  84. -- +migrate Down
  85. DROP TABLE account;
  86. DROP TABLE l2tx;
  87. DROP TABLE l1tx;
  88. DROP TABLE token;
  89. DROP TABLE bid;
  90. DROP TABLE exit_tree;
  91. DROP TABLE batch;
  92. DROP TABLE coordianator;
  93. DROP TABLE slot_min_prices;
  94. DROP TABLE block;