create-db.sql 1.2 KB

1234567891011121314151617181920212223242526272829
  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);