sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

Issue when working with tables that contain slashes

Open samuel-c-allan opened this issue 3 years ago • 2 comments

An interesting bug occurs when working with a database that contains tables with slashes. Here is the output of the process at the time of error:

[Error: ENOENT: no such file or directory, open '/home/sapcs/Softwares/Git/OData4/models/SLOAP/TITLET.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/sapcs/Softwares/Git/OData4/models/SLOAP/TITLET.js'
}

The original table was called '/SLOAP/TITLET' and obviously ended up being references as if it were in a separate directory. This should be a simple bug to fix and I am ready to contribute with a PR if you don't have the time to work on this.

The offending code for reference:

const { pg } = require('../config');
const SequelizeAuto = require('sequelize-auto');

const auto = new SequelizeAuto(pg.database, pg.user, pg.password, {
    host: pg.host,
    dialect: 'postgres',
    port: pg.port,
    dialect: 'postgres'
});

auto.run().then(data => {
	console.log(data);
});

samuel-c-allan avatar Apr 16 '21 00:04 samuel-c-allan

I had not anticipated a table name with slashes! A PR would be most welcome. Thanks!

steveschmitt avatar Apr 16 '21 04:04 steveschmitt

Ok so I forgot about this but slashes are actually illegal in filenames, which means that either some sort of dirty trick (like replace with _) or an entire redesign of the whole system needs to take place.

In our case in particular we can resolve the problem in a different way (by renaming the tables) and honestly it is probably a reasonable assumption that tables will not contain slashes. So feel free to close this issue

samuel-c-allan avatar Apr 20 '21 01:04 samuel-c-allan