dhcpdb_create.mysql 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright (C) 2012 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. # This is the BIND 10 DHCP schema specification for MySQL.
  16. #
  17. # The schema is reasonably portable (with the exception of the engine
  18. # specification, which is MySQL-specific). Minor changes might be needed for
  19. # other databases.
  20. # To create the schema, either type the command:
  21. #
  22. # mysql -u <user> -p <password> <database> < dhcpdb_create.mysql
  23. #
  24. # ... at the command prompt, or log in to the MySQL database and at the "mysql>"
  25. # prompt, issue the command:
  26. #
  27. # source dhcpdb_create.mysql
  28. # Holds the IPv4 leases.
  29. CREATE TABLE lease4 (
  30. address INT UNSIGNED PRIMARY KEY NOT NULL, # IPv4 address
  31. hwaddr VARBINARY(20), # Hardware address
  32. client_id VARBINARY(128), # Client ID
  33. valid_lifetime INT UNSIGNED, # Length of the lease (seconds)
  34. expire TIMESTAMP, # Expiration time of the lease
  35. subnet_id INT UNSIGNED # Subnet identification
  36. ) ENGINE = INNODB;
  37. # Holds the IPv6 leases.
  38. # N.B. The use of a VARCHAR for the address is temporary for development:
  39. # it will eventually be replaced by BINARY(16).
  40. CREATE TABLE lease6 (
  41. address VARCHAR(39) PRIMARY KEY NOT NULL, # IPv6 address
  42. duid VARBINARY(128), # DUID
  43. valid_lifetime INT UNSIGNED, # Length of the lease (seconds)
  44. expire TIMESTAMP, # Expiration time of the lease
  45. subnet_id INT UNSIGNED, # Subnet identification
  46. pref_lifetime INT UNSIGNED, # Preferred lifetime
  47. lease_type TINYINT, # Lease type (see lease6_types
  48. # table for possible values)
  49. iaid INT UNSIGNED, # See Section 10 of RFC 3315
  50. prefix_len TINYINT UNSIGNED # For IA_PD only
  51. ) ENGINE = INNODB;
  52. # ... and a definition of lease6 types. This table is a convenience for
  53. # users of the database - if they want to view the lease table and use the
  54. # type names, they can join this table with the lease6 table
  55. CREATE TABLE lease6_types (
  56. lease_type TINYINT PRIMARY KEY NOT NULL, # Lease type code.
  57. name VARCHAR(5) # Name of the lease type
  58. );
  59. START TRANSACTION;
  60. INSERT INTO lease6_types VALUES (0, "IA_NA"); # Non-temporary v6 addresses
  61. INSERT INTO lease6_types VALUES (1, "IA_TA"); # Temporary v6 addresses
  62. INSERT INTO lease6_types VALUES (2, "IA_PD"); # Prefix delegations
  63. COMMIT;
  64. # Finally, the version of the schema. We start at 0.1 during development.
  65. # This table is only modified during schema upgrades. For historical reasons
  66. # (related to the names of the columns in the BIND 10 DNS database file), the
  67. # first column is called "version" and not "major".
  68. CREATE TABLE schema_version (
  69. version INT PRIMARY KEY NOT NULL, # Major version number
  70. minor INT # Minor version number
  71. );
  72. START TRANSACTION;
  73. INSERT INTO schema_version VALUES (1, 0);
  74. COMMIT;
  75. # Notes:
  76. #
  77. # Indexes
  78. # =======
  79. # It is likely that additional indexes will be needed. However, the
  80. # increase in lookup performance from these will come at the expense
  81. # of a decrease in performance during insert operations due to the need
  82. # to update the indexes. For this reason, the need for additional indexes
  83. # will be determined by experiment during performance tests.
  84. #
  85. # The most likely additional indexes will cover the following columns:
  86. #
  87. # expire
  88. # To speed up the deletion of expired leases from the database.
  89. #
  90. # hwaddr and client_id
  91. # For lease stability: if a client requests a new lease, try to find an
  92. # existing or recently expired lease for it so that it can keep using the
  93. # same IP address.
  94. #
  95. # Field Sizes
  96. # ===========
  97. # If any of the VARxxx field sizes are altered, the lengths in the MySQL
  98. # backend source file (mysql_lease_mgr.cc) must be correspondingly changed.
  99. #
  100. # Portability
  101. # ===========
  102. # The "ENGINE = INNODB" on some tables is not portablea to another database
  103. # and will need to be removed.
  104. #
  105. # Some columns contain binary data so are stored as VARBINARY instead of
  106. # VARCHAR. This may be non-portable between databases: in this case, the
  107. # definition should be changed to VARCHAR.