create-db.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. CREATE TABLE router (
  2. router_id SERIAL PRIMARY KEY,
  3. fingerprint CHAR(40) NOT NULL,
  4. UNIQUE(fingerprint)
  5. );
  6. -- already created implicitly due to unique contraint
  7. -- CREATE INDEX router_fingerprint ON router(fingerprint);
  8. CREATE TABLE nickname (
  9. nickname_id SERIAL PRIMARY KEY,
  10. nick VARCHAR(30) NOT NULL,
  11. UNIQUE(nick)
  12. );
  13. -- already created implicitly due to unique contraint
  14. -- CREATE INDEX nickname_nick ON nickname(nick);
  15. CREATE TABLE router_claims_nickname (
  16. router_id INTEGER NOT NULL REFERENCES router(router_id) ON DELETE CASCADE,
  17. nickname_id INTEGER NOT NULL REFERENCES nickname(nickname_id) ON DELETE CASCADE,
  18. first_seen TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  19. last_seen TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  20. named BOOLEAN NOT NULL DEFAULT 'false',
  21. UNIQUE(router_id, nickname_id)
  22. );
  23. CREATE INDEX router_claims_nickname_router_id ON router_claims_nickname(router_id);
  24. CREATE INDEX router_claims_nickname_nickname_id ON router_claims_nickname(nickname_id);
  25. CREATE INDEX router_claims_nickname_first_seen ON router_claims_nickname(first_seen);
  26. CREATE INDEX router_claims_nickname_last_seen ON router_claims_nickname(last_seen);
  27. -- Copyright (c) 2007 Peter Palfrader
  28. --
  29. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  30. -- of this software and associated documentation files (the "Software"), to deal
  31. -- in the Software without restriction, including without limitation the rights
  32. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  33. -- copies of the Software, and to permit persons to whom the Software is
  34. -- furnished to do so, subject to the following conditions:
  35. --
  36. -- The above copyright notice and this permission notice shall be included in
  37. -- all copies or substantial portions of the Software.
  38. --
  39. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  40. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  41. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  42. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  43. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  44. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  45. -- SOFTWARE.