/**
 * Mermaid Diagrams — per-user clinical pathway / algorithm diagrams.
 * Source is plain Mermaid text; rendered to SVG client-side. Source
 * encrypted at rest like personal_notes so a row dump stays useless
 * without the app key.
 */

exports.up = (pgm) => {
  pgm.createTable('mermaid_diagrams', {
    id:         { type: 'serial', primaryKey: true },
    user_id:    { type: 'integer', notNull: true, references: 'users(id)', onDelete: 'CASCADE' },
    title:      { type: 'text', notNull: true },
    source:     { type: 'text', notNull: true, default: '' },
    notes:      { type: 'text', notNull: true, default: '' },
    created_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
    updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
  });
  pgm.createIndex('mermaid_diagrams', 'user_id');
  pgm.createIndex('mermaid_diagrams', ['user_id', 'updated_at']);
};

exports.down = (pgm) => {
  pgm.dropTable('mermaid_diagrams');
};
