kanel icon indicating copy to clipboard operation
kanel copied to clipboard

Cannot find module when using 2 different schemas with 2 different folders

Open naftis opened this issue 4 years ago • 6 comments

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' };

naftis avatar Oct 15 '20 18:10 naftis

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.

kristiandupont avatar Oct 17 '20 12:10 kristiandupont

This should be working now, let me know if you have further issues!

kristiandupont avatar Nov 03 '20 10:11 kristiandupont

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

amc6 avatar Aug 04 '21 23:08 amc6

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.

kristiandupont avatar Aug 06 '21 09:08 kristiandupont

Hi @kristiandupont, Is there any update/workaround for this? I face the same problem.

mytheen-ls avatar May 25 '22 19:05 mytheen-ls

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.

kristiandupont avatar Jun 01 '22 17:06 kristiandupont

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

kristiandupont avatar Aug 16 '22 14:08 kristiandupont

I was able to resolve a similar by switching to v3 🥳

collin avatar Aug 23 '22 23:08 collin