kanel
kanel copied to clipboard
Cannot find module when using 2 different schemas with 2 different folders
I'm not sure if related to https://github.com/kristiandupont/kanel/issues/15 , but feel free to close this one if it is.
init-db.sql
CREATE SCHEMA test1;
CREATE SCHEMA test2;
CREATE TABLE test1.users (
id integer DEFAULT nextval('test1.users_id_seq'::regclass) PRIMARY KEY
);
CREATE TABLE test2.user_managers (
id integer DEFAULT nextval('test2.user_managers_id_seq'::regclass) PRIMARY KEY,
user_id integer REFERENCES test1.users(id)
);
So basically just 2 schemas with the other one pointing to other one.
.kanelrc.js
const path = require("path");
module.exports = {
// connection: {},
filenameCasing: "dash",
typeCasing: "pascal",
preDeleteModelFolder: true,
schemas: [
{
name: "test1",
modelFolder: path.join(__dirname, "models", "test1"),
},
{
name: "test2",
modelFolder: path.join(__dirname, "models", "test2"),
},
],
};
Output: ./models/test2/user-managers.ts
// Automatically generated. Don't change this file manually.
import { UsersId } from './users'; // <-- ERROR HERE! Refers to same folder, even though the UsersId is in "test1".
export type UserManagersId = number & { __flavor?: 'user_managers' };
Ah, I'm not sure either but this looks like it's something I can easily write a test for so that should be fixable :-) I'll look into it.
This should be working now, let me know if you have further issues!
I seem to be running into this exact same issue on both 2.2.0 and 2.3.0
.kanelrc.js
const path = require('path');
const CONFIDENTIAL_FOLDER = path.join(
__dirname,
'..',
'shared',
'src',
'types',
'database',
'confidential',
);
const PUBLIC_FOLDER = path.join(
__dirname,
'..',
'shared',
'src',
'types',
'database',
'public',
);
const connection = {
host: 'localhost',
user: 'trucksmarter',
password: 'redacted',
database: 'jooqdb',
};
module.exports = {
connection: connection,
preDeleteModelFolder: true,
customTypeMap: {
uuid: {
name: 'UUID',
module: '../../uuid',
absoluteImport: true,
defaultImport: false,
},
geography: 'string', // TODO – this is not correct
bytea: 'string',
// These aren't quite right since a javascript number can't represent very large numbers
int8: 'number',
float8: 'number',
numeric: 'number',
},
schemas: [
{
name: 'confidential',
modelFolder: CONFIDENTIAL_FOLDER,
},
{
name: 'public',
modelFolder: PUBLIC_FOLDER,
ignore: [
'geography_columns',
'geometry_columns',
'spatial_ref_sys',
'flyway_schema_history',
'scheduled_tasks',
],
},
],
};
shared/src/types/database/confidential/one_time_tokens.ts
// @generated
// Automatically generated. Don't change this file manually.
import { usersId } from './users'; // <-- ERROR HERE Its looking in the confidential directory instead of '../public/users'
import { UUID } from '../../uuid';
export type one_time_tokensId = number & { " __flavor"?: 'one_time_tokens' };
export default interface one_time_tokens {
id: one_time_tokensId;
created_at: Date;
last_modified: Date;
/** Index: one_time_tokens_token_key */
token: UUID;
authorized_action: authorizedaction; <-- 2nd ERROR HERE. This isn't being imported at all. However since this is an actual database type, I am able to work around it with customTypeMap
I guess there might still be some cruft with imported types. Unfortunately I am completely swamped at the moment so I will not have the time to look into this before perhaps around October. I am sorry about this, I am happy to assist a bit if you want to make a PR.
Hi @kristiandupont, Is there any update/workaround for this? I face the same problem.
Sorry, I guess this problem remains. I am doing some updates these days, so I will try and see if I can look into this as well.
This should finally be addressed :-)
There is a premajor version out that should fix this issue. There are significant breaking changes though, and the API is not final so feel free to experiment if you like. The documentation is work in progress still, you can start here: https://github.com/kristiandupont/kanel/blob/v3/docs/configuring.md
I was able to resolve a similar by switching to v3 🥳