exports.up = (pgm) => {
  pgm.createTable('travelers', {
    id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
    trip_id: { type: 'uuid', notNull: true, references: 'trips(id)', onDelete: 'CASCADE' },
    linked_user_id: { type: 'uuid', references: 'users(id)' },
    display_name: { type: 'text', notNull: true },
    traveler_type: { type: 'text', notNull: true },
    created_by_user_id: { type: 'uuid', notNull: true, references: 'users(id)' },
    created_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
    updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('now()') },
  });
  pgm.addConstraint(
    'travelers',
    'travelers_traveler_type_check',
    "CHECK (traveler_type IN ('ADULT','CHILD','INFANT'))",
  );
  pgm.createIndex('travelers', 'trip_id');
};

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