Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating a table in knex: storing media, image or a blob

I am trying to migrate a relation to my postgres database. The problem is I have no clue what value type to use for an image.

exports.up = function (knex, Promise) => {
  return knex.schema.createTable('observations', (table) => {
    table.increments();
    table.integer('user_id').notNullable();
    table.blob('image').notNullable(); //???
    table.string('category').notNullable();
    table.string('description').notNullable();
    table.boolean('approved').notNullable().defaultTo(false);
    table.float('latitude').notNullable();
    table.float('longitude').notNullable();
    table.timestamp('created_at').defaultTo(knex.fn.now());
  });
};

I thought there would be a 'blob' file type but in the documentation there seems to be no sign of migrating any media.

Please help me.

like image 234
uzimike Avatar asked Mar 08 '23 10:03

uzimike


1 Answers

Looks like table.binary should fit the bill.

The PostgreSQL data type should be bytea.

like image 62
Laurenz Albe Avatar answered Mar 19 '23 01:03

Laurenz Albe