exports.up = (knex, Promise) => knex.schema.createTable('cohorts', (table) => { table.increments('id') .primary(); table.string('name', 'varchar(6)') .notNullable(); table.string('type', 'varchar(3)') .notNullable(); table.date('q1_start_date') .notNullable(); table.date('q2_start_date') .notNullable(); table.date('q3_start_date') .notNullable(); table.date('q4_start_date') .notNullable(); table.date('graduation_date') .notNullable(); table.integer('campus_id') .notNullable() .references('id') .inTable('campuses') .onDelete('CASCADE'); table.timestamps(true, true); }); exports.down = (knex, Promise) => knex.schema.dropTable('cohorts');Estoy usando postgresql para hacer mi base de datos en la que uso la fecha en mis migraciones cuando reviso mi tabla en la base de datos, está almacenada en el formato de fecha; sin embargo, al escribir mis rutas en bookshelf.js, esas fechas vienen con la marca de tiempo.
cuando el controlador node-postgres lee el tipo de fecha de la columna de la base de datos, lo convierte automáticamente en objeto de fecha de javascript, que en realidad tiene fecha y hora.
Puede configurar el controlador pg para devolver fechas en formato de cadena si lo desea con este paquete https://github.com/brianc/node-pg-types
El tipo de identificación del tipo de fecha es:
mikaelle=# select typname, oid, typarray from pg_type where pg_type.typname = 'date' order by oid; typname | oid | typarray ---------+------+---------- date | 1082 | 1182 (1 row)Y el código para configurar el análisis del tipo se puede hacer así:
var types = require('pg').types types.setTypeParser(1082, function(val) { return val; // just pass the string })