title: Knex error loading SQL FIle - syntax error at or near "undefined"
body: <p>Im sure this is a simple problem but im stuck and Dr Google isn't helping.</p>
  
  <p>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.</p>
  
  <p>Essentially, im loading the SQL files off the file system and <code>knex.raw()</code> applying them.  I can see the SQL is loading up fine, its spitting out into the console.</p>
  
  <p>My migration method looks like</p>
  
  <pre><code>exports.up = knex =&gt; {
      const schemaFilePath = path.join(__dirname, "../db/schema");
      const schemaFiles = fs.readdirSync(schemaFilePath);
      let sql;
      schemaFiles.forEach(async file =&gt; {
          sql += fs.readFileSync(path.join(schemaFilePath, file), "utf8");
      });
      return knex.raw(sql);
  };
  </code></pre>
  
  <p>Theres several SQL files, loaded from that schema directory that look as follows. (with the commented lines etc)</p>
  
  <pre><code>-- 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,
  ....
  </code></pre>
  
  <p>The error I get is </p>
  
  <pre><code>    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)
  </code></pre>
  
  <p>It's not that particular file either as if I just delete that file, I still get the same error, just at another file.</p>
  
  <p>Scrolling through the outputted logs, the SQL all looks fine to me.</p>
  
  <p>Iv checked for bad characters, spaces etc.  I got no where.</p>
  
  <p>Hoping im just doing something wrong here.</p>
  
  <p>Any ideas?</p>