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.

105 lines
3.1 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 coordiantor (
  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. from_idx BIGINT NOT NULL,
  56. to_idx BIGINT NOT NULL,
  57. token_id INT NOT NULL REFERENCES token (token_id),
  58. amount NUMERIC NOT NULL,
  59. nonce BIGINT NOT NULL,
  60. fee INT NOT NULL,
  61. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  62. to_forge_l1_txs_num BIGINT NOT NULL,
  63. position INT NOT NULL,
  64. origin_user BOOLEAN NOT NULL,
  65. from_eth_addr BYTEA NOT NULL,
  66. from_bjj BYTEA NOT NULL,
  67. load_amount BYTEA NOT NULL
  68. );
  69. CREATE TABLE l2tx (
  70. tx_id BYTEA PRIMARY KEY,
  71. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  72. position INT NOT NULL,
  73. from_idx BIGINT NOT NULL,
  74. to_idx BIGINT NOT NULL,
  75. amount NUMERIC NOT NULL,
  76. fee INT NOT NULL,
  77. nonce BIGINT NOT NULL
  78. );
  79. CREATE TABLE account (
  80. idx BIGINT PRIMARY KEY,
  81. token_id INT NOT NULL REFERENCES token (token_id),
  82. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  83. bjj BYTEA NOT NULL,
  84. eth_addr BYTEA NOT NULL
  85. );
  86. -- +migrate Down
  87. DROP TABLE account;
  88. DROP TABLE l2tx;
  89. DROP TABLE l1tx;
  90. DROP TABLE token;
  91. DROP TABLE bid;
  92. DROP TABLE exit_tree;
  93. DROP TABLE batch;
  94. DROP TABLE coordiantor;
  95. DROP TABLE slot_min_prices;
  96. DROP TABLE block;