004.sql 666 B

12345678910111213141516171819
  1. -- Crea la tabla de los tags de las notas.
  2. CREATE TABLE IF NOT EXISTS notes_tags (
  3. id CHAR(36) NOT NULL,
  4. note_id CHAR(36) NOT NULL,
  5. tag_id CHAR(36) NOT NULL,
  6. created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  7. updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  8. CONSTRAINT notes_tags_id_primary PRIMARY KEY(id),
  9. CONSTRAINT notes_tags_note_id_foreign FOREIGN KEY(note_id)
  10. REFERENCES notes(id)
  11. ON DELETE CASCADE
  12. ON UPDATE RESTRICT,
  13. CONSTRAINT notes_tags_tag_id_foreign FOREIGN KEY(tag_id)
  14. REFERENCES tags(id)
  15. ON DELETE CASCADE
  16. ON UPDATE RESTRICT,
  17. CONSTRAINT notes_tags_note_id_tag_id_unique UNIQUE(note_id, tag_id)
  18. );