Giter Site home page Giter Site logo

Comments (7)

hsluoyz avatar hsluoyz commented on July 19, 2024

Can anyone help on this issue? @nodece @stu01509

from typeorm-adapter.

stu01509 avatar stu01509 commented on July 19, 2024

@adrianwix

Can you paste your code and error message? I will get in-depth about this issue.

from typeorm-adapter.

hsluoyz avatar hsluoyz commented on July 19, 2024

@nodece

from typeorm-adapter.

nodece avatar nodece commented on July 19, 2024

It works fine.

const a = await TypeORMAdapter.newAdapter({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: '*******',
  database: 'casbin',
  dropSchema: true
});

from typeorm-adapter.

adrianwix avatar adrianwix commented on July 19, 2024

Hi, sorry for not answering. The problem may be that I am calling dropSchema using the Nestjs module. Without calling the adapter with dropSchema. So the adapter tries to access the table after it has been deleted.

Error:

[Nest] 4696   - 11/01/2020, 5:55:38 PM   [ExceptionHandler] relation "casbin_rule" does not exist +440ms
QueryFailedError: relation "casbin_rule" does not exist
    at new QueryFailedError (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\typeorm\error\QueryFailedError.js:11:28)
    at Query.callback (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\typeorm\driver\postgres\PostgresQueryRunner.js:187:38)
    at Query.handleError (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\pg\lib\query.js:128:19)   
    at Client._handleErrorMessage (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\pg\lib\client.js:326:17)
    at Connection.emit (events.js:311:20)
    at Connection.EventEmitter.emit (domain.js:482:12)
    at C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\pg\lib\connection.js:109:12
    at Parser.parse (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\pg-protocol\dist\parser.js:40:17)
    at Socket.<anonymous> (C:\Users\Adrian Wix\Code\posterlab\posterlab-mvp\nest-backend\node_modules\pg-protocol\dist\index.js:10:42)
    at Socket.emit (events.js:311:20)

Nestjs config

TypeOrmModule.forRootAsync({
            useFactory: (config: ConfigService) => {
                return {
                    type: 'postgres',
                    host: config.get('DATABASE_HOST'),
                    port: config.get<number>('DATABASE_PORT'),
                    username: config.get('DATABASE_USERNAME'),
                    password: config.get('DATABASE_PASSWORD'),
                    database: config.get('DATABASE_NAME'),
                    entities,
                    logging: config.get('NODE_ENV') === 'development',
                    // migrationsRun: config.get('NODE_ENV') !== 'test',
                    dropSchema: true,
                    synchronize: config.get('NODE_ENV') === 'test' || true,
                    migrations: [
                        config.get('NODE_ENV') === 'test'
                            ? join(
                                  __dirname,
                                  '../',
                                  'src/database/migrations/**/*{.ts,.js}',
                              )
                            : join(
                                  __dirname,
                                  'database/migrations/**/*{.ts,.js}',
                              ),
                    ],
                    keepConnectionAlive: true,
                }
            },
            inject: [ConfigService],
        }),

Casbin adapter

{
            provide: CASBIN_ENFORCER,
            useFactory: async (config: ConfigService) => {
                // TODO: Use a different connection
                const adapter = await TypeORMAdapter.newAdapter({
                    type: 'postgres',
                    host: config.get('DATABASE_HOST'),
                    port: config.get<number>('DATABASE_PORT'),
                    username: config.get('DATABASE_USERNAME'),
                    password: config.get('DATABASE_PASSWORD'),
                    database: config.get('DATABASE_NAME'),
                    // dropSchema: true
                })
                // const adapter = join(process.cwd(), 'dist/iam/policy.csv')
                const e = await newEnforcer(
                    join(process.cwd(), 'dist/iam/models/default.conf'),
                    adapter,
                )

                e.addFunction('keyMatch2', keyMatch2Func)
                e.addFunction('keyMatch', keyMatchFunc)

                return e
            },
            inject: [ConfigService],
        },

EDIT: Sorry for the vague question. My brain wasn't working anymore at that hour...

from typeorm-adapter.

nodece avatar nodece commented on July 19, 2024

@adrianwix Could you try to initialize TypeORM first and then Casbin Adapter?

Maybe adding dropSchema is not a good idea :(

from typeorm-adapter.

hsluoyz avatar hsluoyz commented on July 19, 2024

Closed as stale.

from typeorm-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.