dhcpdb_create.mysql 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. lease_time 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(40) PRIMARY KEY NOT NULL, # IPv6 address
  42. hwaddr VARBINARY(20), # Hardware address
  43. client_id VARBINARY(128), # Client ID
  44. lease_time INT UNSIGNED, # Length of the lease (seconds)
  45. expire TIMESTAMP, # Expiration time of the lease
  46. subnet_id INT UNSIGNED, # Subnet identification
  47. pref_lifetime INT UNSIGNED, # Preferred lifetime
  48. lease_type TINYINT, # Lease type (see lease6_types
  49. # table for possible values)
  50. iaid INT UNSIGNED, # See Section 10 of RFC 3315
  51. prefix_len TINYINT UNSIGNED # For IA_PD only
  52. ) ENGINE = INNODB;
  53. # ... and a definition of lease6 types. This table is a convenience for
  54. # users of the database - if they want to view the lease table and use the
  55. # type names, they can join this table with the lease6 table
  56. CREATE TABLE lease6_types (
  57. lease_type TINYINT PRIMARY KEY NOT NULL, # Lease type code.
  58. name VARCHAR(5) # Name of the lease type
  59. );
  60. START TRANSACTION;
  61. INSERT INTO lease6_types VALUES (0, "IA_NA"); # Non-temporary v6 addresses
  62. INSERT INTO lease6_types VALUES (1, "IA_TA"); # Temporary v6 addresses
  63. INSERT INTO lease6_types VALUES (2, "IA_PD"); # Prefix delegations
  64. COMMIT;
  65. # Finally, the version of the schema. We start at 0.1 during development.
  66. # This table is only modified during schema upgrades. For historical reasons
  67. # (related to the names of the columns in the BIND 10 DNS database file), the
  68. # first column is called "version" and not "major".
  69. CREATE TABLE schema_version (
  70. version INT PRIMARY KEY NOT NULL, # Major version number
  71. minor INT # Minor version number
  72. );
  73. START TRANSACTION;
  74. INSERT INTO schema_version VALUES (0, 1);
  75. COMMIT;
  76. # Notes:
  77. #
  78. # Indexes
  79. # =======
  80. # It is likely that additional indexes will be needed. However, the
  81. # increase in lookup performance from these will come at the expense
  82. # of a decrease in performance during insert operations due to the need
  83. # to update the indexes. For this reason, the need for additional indexes
  84. # will be determined by experiment during performance tests.
  85. #
  86. # The most likely additional indexes will cover the following columns:
  87. #
  88. # expire
  89. # To speed up the deletion of expired leases from the database.
  90. #
  91. # hwaddr and client_id
  92. # For lease stability: if a client requests a new lease, try to find an
  93. # existing or recently expired lease for it so that it can keep using the
  94. # same IP address.
  95. #
  96. # Field Sizes
  97. # ===========
  98. # If any of the VARxxx field sizes are altered, the lengths in the MySQL
  99. # backend source file (mysql_lease_mgr.cc) must be correspondingly changed.
  100. #
  101. # Portability
  102. # ===========
  103. # The "ENGINE = INNODB" on some tables is not portablea to another database
  104. # and will need to be removed.
  105. #
  106. # Some columns contain binary data so are stored as VARBINARY instead of
  107. # VARCHAR. This may be non-portable between databases: in this case, the
  108. # definition should be changed to VARCHAR.