<@U01MV4U2EV9> <@U01JVDKASAC> bringing this error ...
# sst
j
@thdxr @Frank bringing this error over from the Kysely discord, I’m trying to run my initial migration on a greenfield project, but Kysely is erroring with
Error: invalid immediate value [object Object]
and it sounds like it has got two different versions of Kysely somehow. This is using Postgres on Aurora.
Here is my migration file
Copy code
import { sql, Kysely, Transaction } from "kysely";

export async function up(db) {
  console.log(db.constructor === Kysely, db.constructor === Transaction);
	// Migration code
	await db.schema
		.createTable("customer_profile")
		.addColumn("id", "uuid", (col) =>
			col.primaryKey().defaultTo(sql`gen_random_uuid()`)
		)
		.addColumn("first_name", "varchar", (col) => col.notNull())
		.addColumn("last_name", "varchar", (col) => col.notNull())
		.addColumn("account_id", "varchar(128)", (col) => col.notNull())
		.addColumn("created_at", "TIMESTAMP", (col) =>
			col.notNull().generatedAlwaysAs(sql`now()`)
		)
		.addColumn("modified_at", "TIMESTAMP")
		.addColumn("version", "integer", (col) => col.notNull().defaultTo(1))
		.execute();
}

export async function down(db) {
	// Migration code
	await db.schema.dropTable("customer_profile").execute();
}
The
console.log
should report one of them as
true
but I get both as
false, false
which indicates the kysely I’m importing is not the same version of kysely as the migration gets invoked with.
t
I know why this is happening let me try to figure out a fix today
j
Thanks!
Let me know if you want me to test a fix
t
@jamlen what version of sst have you been trying?
j
@thdxr v1.2.15
t
ok cool can you run
yarn sst update snapshot
I think the root issue was our migrator script was not using ESM, which meant it imported the cjs version of kysely hence the mismatch
I updated it to use ESM (which had a dozen side effects as usual 😅 ) but I think it's working - I at least got it to print true for transaction = Kysely
j
Just trying it now… I also noticed that if you name your migration files with dots it doesn’t like it! e.g.
2022.06.04-14.36.23.365-Initial.mjs
the console only sees it as
2022
and then says file not found! I just renamed it so its fine, but a little gotcha
t
ah interesting
oh also you need to update your
kysely-data-api
package to 0.0.11
j
So now I get the
true
in one of the consoles, but it errors with
ERROR BadRequestException: ERROR: syntax error at or near "("
which might be my migration script itself 😉
Although I don’t think I’m doing anything too crazy
t
you're close! you can try doing
.compile()
instead of
.execute()
and logging
see if you can spot the error in the sql
j
heres the sql
Copy code
sql: 'create table "customer_profile" ("id" uuid default gen_random_uuid() primary key, "first_name" varchar not null, "last_name" varchar not null, "account_id" varchar(128) not null, "created_at" TIMESTAMP generated always as (now()) not null, "modified_at" TIMESTAMP, "version" integer default 1 not null)'
I think it will be the
created_at
column… and the
generated always as
- I’ll remove that and see if it works
Looks like you’re stuff works, now just my script and setup.
Copy code
ERROR BadRequestException: ERROR: function gen_random_uuid() does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.; SQLState: 42883
t
cool, there's actually a bug in that snapshot build on deploy so fixing that then will release
j
Thanks Dax, I'll pull the latest in the morning.
Looks like its working nicely. Thanks again @thdxr