schema_copy.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (C) 2012-2013 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 MySQL 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.mysql.
  25. // If this file is altered, please ensure that any change is compatible
  26. // with the schema in dhcpdb_create.mysql.
  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 INT UNSIGNED PRIMARY KEY NOT NULL,"
  40. "hwaddr VARBINARY(20),"
  41. "client_id VARBINARY(128),"
  42. "valid_lifetime INT UNSIGNED,"
  43. "expire TIMESTAMP,"
  44. "subnet_id INT UNSIGNED,"
  45. "fqdn_fwd BOOL,"
  46. "fqdn_rev BOOL,"
  47. "hostname VARCHAR(255)"
  48. ") ENGINE = INNODB",
  49. "CREATE INDEX lease4_by_hwaddr_subnet_id ON lease4 (hwaddr, subnet_id)",
  50. "CREATE INDEX lease4_by_client_id_subnet_id ON lease4 (client_id, subnet_id)",
  51. "CREATE TABLE lease6 ("
  52. "address VARCHAR(39) PRIMARY KEY NOT NULL,"
  53. "duid VARBINARY(128),"
  54. "valid_lifetime INT UNSIGNED,"
  55. "expire TIMESTAMP,"
  56. "subnet_id INT UNSIGNED,"
  57. "pref_lifetime INT UNSIGNED,"
  58. "lease_type TINYINT,"
  59. "iaid INT UNSIGNED,"
  60. "prefix_len TINYINT UNSIGNED,"
  61. "fqdn_fwd BOOL,"
  62. "fqdn_rev BOOL,"
  63. "hostname VARCHAR(255)"
  64. ") ENGINE = INNODB",
  65. "CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid)",
  66. "CREATE TABLE lease6_types ("
  67. "lease_type TINYINT PRIMARY KEY NOT NULL,"
  68. "name VARCHAR(5)"
  69. ")",
  70. "INSERT INTO lease6_types VALUES (0, \"IA_NA\")",
  71. "INSERT INTO lease6_types VALUES (1, \"IA_TA\")",
  72. "INSERT INTO lease6_types VALUES (2, \"IA_PD\")",
  73. "CREATE TABLE schema_version ("
  74. "version INT PRIMARY KEY NOT NULL,"
  75. "minor INT"
  76. ")",
  77. "INSERT INTO schema_version VALUES (1, 0)",
  78. "COMMIT",
  79. NULL
  80. };
  81. }; // Anonymous namespace
  82. #endif // SCHEMA_COPY_H