schema_pgsql_copy.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef SCHEMA_COPY_H
  15. #define SCHEMA_COPY_H
  16. namespace {
  17. // What follows is a set of statements that creates a copy of the schema
  18. // in the test database. It is used by the PostgreSQL unit test prior to each
  19. // test.
  20. //
  21. // Each SQL statement is a single string. The statements are not terminated
  22. // by semicolons, and the strings must end with a comma. The final line
  23. // statement must be NULL (not in quotes)
  24. // NOTE: This file mirrors the schema in src/lib/dhcpsrv/dhcpdb_create.pgsql.
  25. // If this file is altered, please ensure that any change is compatible
  26. // with the schema in dhcpdb_create.pgsql.
  27. // Deletion of existing tables.
  28. const char* destroy_statement[] = {
  29. "DROP TABLE lease4",
  30. "DROP TABLE lease6",
  31. "DROP TABLE lease6_types",
  32. "DROP TABLE schema_version",
  33. NULL
  34. };
  35. // Creation of the new tables.
  36. const char* create_statement[] = {
  37. "START TRANSACTION",
  38. "CREATE TABLE lease4 ("
  39. "address BIGINT PRIMARY KEY NOT NULL,"
  40. "hwaddr BYTEA,"
  41. "client_id BYTEA,"
  42. "valid_lifetime BIGINT,"
  43. "expire TIMESTAMP WITH TIME ZONE,"
  44. "subnet_id BIGINT,"
  45. "fqdn_fwd BOOLEAN,"
  46. "fqdn_rev BOOLEAN,"
  47. "hostname VARCHAR(255)"
  48. ")",
  49. "CREATE TABLE lease6 ("
  50. "address VARCHAR(39) PRIMARY KEY NOT NULL,"
  51. "duid BYTEA,"
  52. "valid_lifetime BIGINT,"
  53. "expire TIMESTAMP WITH TIME ZONE,"
  54. "subnet_id BIGINT,"
  55. "pref_lifetime BIGINT,"
  56. "lease_type SMALLINT,"
  57. "iaid BIGINT,"
  58. "prefix_len SMALLINT,"
  59. "fqdn_fwd BOOLEAN,"
  60. "fqdn_rev BOOLEAN,"
  61. "hostname VARCHAR(255)"
  62. ")",
  63. "CREATE TABLE lease6_types ("
  64. "lease_type SMALLINT PRIMARY KEY NOT NULL,"
  65. "name VARCHAR(5)"
  66. ")",
  67. "INSERT INTO lease6_types VALUES (0, 'IA_NA')",
  68. "INSERT INTO lease6_types VALUES (1, 'IA_TA')",
  69. "INSERT INTO lease6_types VALUES (2, 'IA_PD')",
  70. "CREATE TABLE schema_version ("
  71. "version INT PRIMARY KEY NOT NULL,"
  72. "minor INT"
  73. ")",
  74. "INSERT INTO schema_version VALUES (1, 0)",
  75. "COMMIT",
  76. // This line concludes creation of database version 1.0.
  77. // Schema upgrade to 2.0 starts here.
  78. "ALTER TABLE lease4 "
  79. "ADD COLUMN state INT8 DEFAULT 0",
  80. "ALTER TABLE lease6 "
  81. "ADD COLUMN state INT8 DEFAULT 0",
  82. "CREATE INDEX lease4_by_state_expire ON lease4 (state, expire)",
  83. "CREATE INDEX lease6_by_state_expire ON lease6 (state, expire)",
  84. // Production schema includes the lease_state table which maps
  85. // the lease states to their names. This is not used in the unit tests
  86. // so it is commented out.
  87. /*"CREATE TABLE lease_state (",
  88. "state INT8 PRIMARY KEY NOT NULL,"
  89. "name VARCHAR(64) NOT NULL);",
  90. "INSERT INTO lease_state VALUES (0, \"default\");",
  91. "INSERT INTO lease_state VALUES (1, \"declined\");",
  92. "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");",*/
  93. "UPDATE schema_version SET version = '2', minor = '0';",
  94. "COMMIT",
  95. // Schema upgrade to 2.0 ends here.
  96. NULL
  97. };
  98. }; // Anonymous namespace
  99. #endif // SCHEMA_COPY_H