Bruno Cruz
Bruno Cruz
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
Thank you for your help so far. Maybe installing kysely package directly can help. I'll report back what I find.
17 replies
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
It prints false
17 replies
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
and this is my migrate-to-latest.js file:
import {
FileMigrationProvider,
Kysely,
Migrator,
PostgresDialect,
} from "kysely";
import pg from "pg";
import { promises as fs } from "fs";
import path from "path";

export async function migrateToLatest() {
const __dirname = path.resolve(path.dirname(""));

const db = new Kysely({
dialect: new PostgresDialect({
pool: new pg.Pool({
host: "localhost",
port: 5432,
user: "postgres",
password: "postgres",
database: "postgres",
}),
}),
});

const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.join(__dirname, "packages/core/migrations"),
}),
});
const { error, results } = await migrator.migrateToLatest();

results?.forEach((it) => {
if (it.status === "Success") {
console.log(`migration "${it.migrationName}" was executed successfully`);
} else if (it.status === "Error") {
console.error(`failed to execute migration "${it.migrationName}"`);
}
});

if (error) {
console.error("failed to migrate");
console.error(error);
process.exit(1);
}

return db;
}

migrateToLatest();
import {
FileMigrationProvider,
Kysely,
Migrator,
PostgresDialect,
} from "kysely";
import pg from "pg";
import { promises as fs } from "fs";
import path from "path";

export async function migrateToLatest() {
const __dirname = path.resolve(path.dirname(""));

const db = new Kysely({
dialect: new PostgresDialect({
pool: new pg.Pool({
host: "localhost",
port: 5432,
user: "postgres",
password: "postgres",
database: "postgres",
}),
}),
});

const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.join(__dirname, "packages/core/migrations"),
}),
});
const { error, results } = await migrator.migrateToLatest();

results?.forEach((it) => {
if (it.status === "Success") {
console.log(`migration "${it.migrationName}" was executed successfully`);
} else if (it.status === "Error") {
console.error(`failed to execute migration "${it.migrationName}"`);
}
});

if (error) {
console.error("failed to migrate");
console.error(error);
process.exit(1);
}

return db;
}

migrateToLatest();
17 replies
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
this is my full example:
import { sql } from "kysely";

export async function up(db) {
// create extension for uuid
await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);

// create product table
await db.schema
.createTable("product")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`uuid_generate_v4()`)
)
.addColumn("name", "text", (col) => col.notNull())
.addColumn("sku", "text")
.addColumn("brand", "text")
.addColumn("store", "text", (col) => col.notNull())
.addColumn("store_url", "text", (col) => col.notNull())
.addColumn("description", "text")
// .addColumn("old_price", "decimal(12,2)", (col) => col.notNull())
// .addColumn("price", "decimal(12,2)", (col) => col.notNull())
.addColumn("old_price", "decimal", (col) => col.notNull())
.addColumn("price", "decimal", (col) => col.notNull())
.addColumn("currency", "text", (col) => col.notNull())
.addColumn("installments_quantity", "text")
.addColumn("installments_value", "text")
.addColumn("available", "boolean", (col) => col.defaultTo(false))
.addColumn("sizes", "jsonb", (col) => col.defaultTo([]))
.addColumn("images", "jsonb", (col) => col.defaultTo([]))
.addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.addColumn("updated_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.$call((qb) => {
console.log(qb.compile());
return qb;
})
.execute();
}

export async function down(db) {
await db.schema.dropTable("product").execute(db);
}
import { sql } from "kysely";

export async function up(db) {
// create extension for uuid
await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);

// create product table
await db.schema
.createTable("product")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`uuid_generate_v4()`)
)
.addColumn("name", "text", (col) => col.notNull())
.addColumn("sku", "text")
.addColumn("brand", "text")
.addColumn("store", "text", (col) => col.notNull())
.addColumn("store_url", "text", (col) => col.notNull())
.addColumn("description", "text")
// .addColumn("old_price", "decimal(12,2)", (col) => col.notNull())
// .addColumn("price", "decimal(12,2)", (col) => col.notNull())
.addColumn("old_price", "decimal", (col) => col.notNull())
.addColumn("price", "decimal", (col) => col.notNull())
.addColumn("currency", "text", (col) => col.notNull())
.addColumn("installments_quantity", "text")
.addColumn("installments_value", "text")
.addColumn("available", "boolean", (col) => col.defaultTo(false))
.addColumn("sizes", "jsonb", (col) => col.defaultTo([]))
.addColumn("images", "jsonb", (col) => col.defaultTo([]))
.addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.addColumn("updated_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.$call((qb) => {
console.log(qb.compile());
return qb;
})
.execute();
}

export async function down(db) {
await db.schema.dropTable("product").execute(db);
}
am I using the wrong package?
17 replies
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
How so? I haven't installed Kysely, it was automatically installed from SST. How can I fix it?
17 replies
KKysely
Created by Bruno Cruz on 5/17/2023 in #help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
Update: I changed my code slightly and am getting a different error. after adding db:
await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);
await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);
But I'm still getting an error:
failed to execute migration "2023051601_create-product-table"
failed to migrate
Error: invalid immediate value
at PostgresQueryCompiler.appendImmediateValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:976:19)
at PostgresQueryCompiler.visitValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:260:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitDefaultValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:812:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitColumnDefinition (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:365:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.compileList (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:115:18)
at PostgresQueryCompiler.visitCreateTable (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:337:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
failed to execute migration "2023051601_create-product-table"
failed to migrate
Error: invalid immediate value
at PostgresQueryCompiler.appendImmediateValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:976:19)
at PostgresQueryCompiler.visitValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:260:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitDefaultValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:812:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitColumnDefinition (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:365:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.compileList (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:115:18)
at PostgresQueryCompiler.visitCreateTable (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:337:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
`
17 replies