schema.sql.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #define ZT_NETCONF_SCHEMA_SQL \
  2. "CREATE TABLE Config (\n"\
  3. " k varchar(16) PRIMARY KEY NOT NULL,\n"\
  4. " v varchar(1024) NOT NULL\n"\
  5. ");\n"\
  6. "\n"\
  7. "CREATE TABLE Network (\n"\
  8. " id char(16) PRIMARY KEY NOT NULL,\n"\
  9. " name varchar(128) NOT NULL,\n"\
  10. " private integer NOT NULL DEFAULT(1),\n"\
  11. " enableBroadcast integer NOT NULL DEFAULT(1),\n"\
  12. " allowPassiveBridging integer NOT NULL DEFAULT(0),\n"\
  13. " multicastLimit integer NOT NULL DEFAULT(32),\n"\
  14. " creationTime integer NOT NULL DEFAULT(0),\n"\
  15. " revision integer NOT NULL DEFAULT(1),\n"\
  16. " memberRevisionCounter integer NOT NULL DEFAULT(1),\n"\
  17. " flags integer NOT NULL DEFAULT(0)\n"\
  18. ");\n"\
  19. "\n"\
  20. "CREATE TABLE AuthToken (\n"\
  21. " id integer PRIMARY KEY NOT NULL,\n"\
  22. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  23. " authMode integer NOT NULL DEFAULT(1),\n"\
  24. " useCount integer NOT NULL DEFAULT(0),\n"\
  25. " maxUses integer NOT NULL DEFAULT(0),\n"\
  26. " expiresAt integer NOT NULL DEFAULT(0),\n"\
  27. " token varchar(256) NOT NULL\n"\
  28. ");\n"\
  29. "\n"\
  30. "CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token);\n"\
  31. "\n"\
  32. "CREATE TABLE Node (\n"\
  33. " id char(10) PRIMARY KEY NOT NULL,\n"\
  34. " identity varchar(4096) NOT NULL\n"\
  35. ");\n"\
  36. "\n"\
  37. "CREATE TABLE IpAssignment (\n"\
  38. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  39. " nodeId char(10) REFERENCES Node(id) ON DELETE CASCADE,\n"\
  40. " type integer NOT NULL DEFAULT(0),\n"\
  41. " ip blob(16) NOT NULL,\n"\
  42. " ipNetmaskBits integer NOT NULL DEFAULT(0),\n"\
  43. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  44. ");\n"\
  45. "\n"\
  46. "CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
  47. "\n"\
  48. "CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);\n"\
  49. "\n"\
  50. "CREATE TABLE IpAssignmentPool (\n"\
  51. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  52. " ipRangeStart blob(16) NOT NULL,\n"\
  53. " ipRangeEnd blob(16) NOT NULL,\n"\
  54. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  55. ");\n"\
  56. "\n"\
  57. "CREATE UNIQUE INDEX IpAssignmentPool_networkId_ipRangeStart ON IpAssignmentPool (networkId,ipRangeStart);\n"\
  58. "\n"\
  59. "CREATE TABLE Member (\n"\
  60. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  61. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  62. " authorized integer NOT NULL DEFAULT(0),\n"\
  63. " activeBridge integer NOT NULL DEFAULT(0),\n"\
  64. " memberRevision integer NOT NULL DEFAULT(0),\n"\
  65. " flags integer NOT NULL DEFAULT(0),\n"\
  66. " lastRequestTime integer NOT NULL DEFAULT(0),\n"\
  67. " lastPowDifficulty integer NOT NULL DEFAULT(0),\n"\
  68. " lastPowTime integer NOT NULL DEFAULT(0),\n"\
  69. " recentHistory blob,\n"\
  70. " PRIMARY KEY (networkId, nodeId)\n"\
  71. ");\n"\
  72. "\n"\
  73. "CREATE INDEX Member_networkId_nodeId ON Member(networkId,nodeId);\n"\
  74. "CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
  75. "CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision);\n"\
  76. "CREATE INDEX Member_networkId_lastRequestTime ON Member(networkId, lastRequestTime);\n"\
  77. "\n"\
  78. "CREATE TABLE Route (\n"\
  79. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  80. " target blob(16) NOT NULL,\n"\
  81. " via blob(16),\n"\
  82. " targetNetmaskBits integer NOT NULL,\n"\
  83. " ipVersion integer NOT NULL,\n"\
  84. " flags integer NOT NULL,\n"\
  85. " metric integer NOT NULL\n"\
  86. ");\n"\
  87. "\n"\
  88. "CREATE INDEX Route_networkId ON Route (networkId);\n"\
  89. "\n"\
  90. "CREATE TABLE Relay (\n"\
  91. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  92. " address char(10) NOT NULL,\n"\
  93. " phyAddress varchar(64) NOT NULL\n"\
  94. ");\n"\
  95. "\n"\
  96. "CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address);\n"\
  97. "\n"\
  98. "CREATE TABLE Rule (\n"\
  99. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  100. " policyId varchar(32),\n"\
  101. " ruleNo integer NOT NULL,\n"\
  102. " ruleType integer NOT NULL DEFAULT(0),\n"\
  103. " \"addr\" blob(16),\n"\
  104. " \"int1\" integer,\n"\
  105. " \"int2\" integer,\n"\
  106. " \"int3\" integer,\n"\
  107. " \"int4\" integer\n"\
  108. ");\n"\
  109. "\n"\
  110. "CREATE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);\n"\
  111. "CREATE INDEX Rule_networkId_policyId ON Rule (networkId, policyId);\n"\
  112. ""