Im sure this is a simple problem but im stuck and Dr Google isn't helping.
Basically im trying to load schema SQL files in a migration using Knex in Node. The SQL files are directly from PGAdmin, no data, just schema.
Essentially, im loading the SQL files off the file system and knex.raw() applying them. I can see the SQL is loading up fine, its spitting out into the console.
My migration method looks like
exports.up = knex => {
const schemaFilePath = path.join(__dirname, "../db/schema");
const schemaFiles = fs.readdirSync(schemaFilePath);
let sql;
schemaFiles.forEach(async file => {
sql += fs.readFileSync(path.join(schemaFilePath, file), "utf8");
});
return knex.raw(sql);
};
Theres several SQL files, loaded from that schema directory that look as follows. (with the commented lines etc)
-- Table: public.roles
-- DROP TABLE public.roles;
CREATE TABLE public.roles
(
_id uuid NOT NULL DEFAULT uuid_generate_v4(),
"displayName" citext COLLATE pg_catalog."default",
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
"_fullTextSearch" citext COLLATE pg_catalog."default",
system boolean DEFAULT false,
....
The error I get is
ON public.validations USING btree
("updatedAt" ASC NULLS LAST)
TABLESPACE pg_default;
- syntax error at or near "undefined"
error: syntax error at or near "undefined"
at Connection.parseE (/xxx/node_modules/pg/lib/connection.js:604:13)
It's not that particular file either as if I just delete that file, I still get the same error, just at another file.
Scrolling through the outputted logs, the SQL all looks fine to me.
Iv checked for bad characters, spaces etc. I got no where.
Hoping im just doing something wrong here.
Any ideas?