mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-04-23 06:30:00 +08:00

### What problem does this PR solve? Fix #6334 Hello, I encountered the same problem in #6334. In the `api/db/db_models.py`, it calls `obj.create_table()` unconditionally in `init_database_tables`, before the `migrate_db()`. Specially for the `permission` field of `user_canvas` table, it has `index=True`, which causes `peewee` to issue a SQL trying to create the index when the field does not exist (the `user_canvas` table already exists), so `psycopg2.errors.UndefinedColumn: column "permission" does not exist` occurred. I've added a judgement in the code, to only call `create_table()` when the table does not exist, delegate the migration process to `migrate_db()`. Then another problem occurs: the `migrate_db()` actually does nothing because it failed on the first migration! The `playhouse` blindly issue DDLs without things like `IF NOT EXISTS`, so it fails... even if the exception is `pass`, the transaction is still rolled back. So I removed the transaction in `migrate_db()` to make it work. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):