Hey, I'm getting an issue testing out the Postgres...
# help
j
Hey, I'm getting an issue testing out the PostgresSQL RDS Instance. I ran
sst:deploy
and it seems to run fine without issues, and then I ran
sst:start
and also seems fine. But when I go to apply the one migration I have, it's coming with this error and after looking at it, doesn't seem like it was run at all.
Copy code
ERROR TypeError: Unknown file extension ".ts" for /home/test-postgres/stacks/db-migrations/2022-02-20.ts 
 TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/test-postgres/stacks/db-migrations/2022-02-20.ts
    at new NodeError (internal/errors.js:322:7)
    at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
    at Loader.getFormat (internal/modules/esm/loader.js:105:42)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
    at async Loader.import (internal/modules/esm/loader.js:177:17)
    at async DynamicFileMigrationProvider.getMigrations (/home/test-postgres/.sst/artifacts/dev-klic-weather-station-StatickStack-RDSCluster-MigrationFunction/home/test-postgres/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:13236:27)
    at async Migrator.resolveMigrations_fn (/home/test-postgres/.sst/artifacts/dev-klic-weather-station-StatickStack-RDSCluster-MigrationFunction/home/test-postgres/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:12040:25)
    at async Migrator.getMigrations (/home/test-postgres/.sst/artifacts/dev-klic-weather-station-StatickStack-RDSCluster-MigrationFunction/home/test-postgres/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:11899:24)
    at async Runtime.handler (/home/test-postgres/.sst/artifacts/dev-klic-weather-station-StatickStack-RDSCluster-MigrationFunction/home/test-postgres/node_modules/@serverless-stack/resources/dist/RDS_migrator/index.js:13220:12)
The migration file is just called
2022-02-20.ts
and contains the following:
Copy code
import { Kysely, sql } from 'kysely';

export async function up(db: Kysely<any>): Promise<void> {
  await sql`CREATE EXTENSION postgis`.execute(db);
}

export async function down(db: Kysely<any>): Promise<void> {
  await sql`DROP EXTENSION extensionName;`.execute(db);
}
So looks like it's not transpiling that TS file before running the migration? Is this expected or is there something that I should be enabling?
t
Hey right now the migrations have to be in js
we have an idea for how to implement ts support but it's not there yet
j
OK, gotcha. Yea, now that I've updated to use JS. It is having issues with me trying to run one of the functions from
kysely
directly. It looks like as
kysely
is actually transpiled for the
MigrationFunction
so it is no longer valid. Any possibilities of keeping that library out in
node_modules
so its not bundled together?
t
can you share the code? would like to understand better what you're doing
j
Migration code
Copy code
const sql = require('kysely').sql;

async function up(db) {
  await sql`CREATE EXTENSION postgis`.execute(db);
}

async function down(db) {
  await sql`DROP EXTENSION extensionName;`.execute(db);
}

module.exports = { up, down };
As you can see
require('kysely');
fails as there is no kysely module.
f
@thdxr is there a way to rewrite
CREATE EXTENSION
with something like this
Copy code
async function up(db) {
  await db.schema
    .createExtension("postgis")
    .execute()
}
j
Unfortunately
kisely
doesn't have any methods that I could find on their docs around extensions
t
Can you try
Copy code
db.raw("CREATE EXTENSION postgis").execute()
j
Cool! Yea that seems to work. Is this an undocumented method? As I looked through Kisely's docs for a bit there to see if there was a way to get this.
t
I see tsdocs for it so I don't think it's undocumented but glad it worked
j
can you link me to the docs? Just curious why it wasn't showing up for me