Как использовать TypeORM с существующей базой данных MySQL (ранее управляемой Laraval) [закрыто]MySql

Форум по Mysql
Ответить
Anonymous
 Как использовать TypeORM с существующей базой данных MySQL (ранее управляемой Laraval) [закрыто]

Сообщение Anonymous »

Вопрос
Я переношу серверную часть с Laravel (PHP) на NestJS, продолжая использовать существующую базу данных MySQL.
База данных уже существует и содержит около 300 таблиц. Некоторые из этих таблиц не имеют первичных ключей, но в настоящее время они используются приложением (в основном таблицы отображения/журнала).
Я пытаюсь использовать TypeORM с подходом «сначала БД».
Что я пробовал
Я пытался генерировать объекты, используя:

Код: Выделить всё

typeorm-model-generator@0.4.6
Node.js v24.x
MySQL 8.x
NestJS + TypeORM
Однако создание сущности для таблиц без первичных ключей завершается неудачно с такими ошибками, как:

Код: Выделить всё

typeorm-model-generator@0.4.6
[1:13:00 PM] Using configuration file. [D:\temp\nestjs-starter-kit\.tomg-config]
? Choose database engine mysql
? Database address: 127.0.0.1
? Database port: 3306
? Use SSL: Yes
? Database user name: root
? Database user password: [hidden]
? Database name: (You can pass multiple values separated by comma) searchy
? Generate schema for tables: All of them
? Path where generated models should be stored: D:\temp\nestjs-starter-kit\output
? Do you want to customize generated model? Yes
? Available customizations Generate config files, Pluralize OneToMany, ManyToMany relation names
? Defines which visibility should have the generated property none
? Mark fields as optional(?) or non-null(!) ?
? Save configuration to config file? Yes, only model customization options
[1:14:12 PM] Config file saved.
[1:14:12 PM] Starting creation of model classes.
Table facebook_form_mappings has no PK.
Error occurred in typeorm-model-generator.
typeorm-model-generator@0.4.6  node@v24.2.0
If you think this is a bug please open an issue including this log on https://github.com/Kononnable/typeorm-model-generator/issues
Table groupcontacts has no PK.
Error occurred in typeorm-model-generator.
typeorm-model-generator@0.4.6  node@v24.2.0
If you think this is a bug please open an issue including this log on https://github.com/Kononnable/typeorm-model-generator/issues
Table link_pixel has no PK.
Error occurred in typeorm-model-generator.
typeorm-model-generator@0.4.6  node@v24.2.0
If you think this is a bug please open an issue including this log on https://github.com/Kononnable/typeorm-model-generator/issues
There were some problems with model generation for table:  orders
SyntaxError: ',' expected.  (121:69)
119 | isCouponSystemActive?:boolean | null;
120 |
> 121 | @Column("varchar",{ name:"tax_method",length:191,default: () => "'{"vat_tax_type" : "","tax_type" : "" }'", })
|                                                                     ^
122 | taxMethod?:string;
123 |
124 | @Column("timestamp",{ name:"created_at",nullable:true })
at v (D:\temp\nestjs-starter-kit\node_modules\prettier\parser-typescript.js:1:14679)
at _H (D:\temp\nestjs-starter-kit\node_modules\prettier\parser-typescript.js:49:10722)
at Object.cH [as parse] (D:\temp\nestjs-starter-kit\node_modules\prettier\parser-typescript.js:49:11028)
at Object.parse (D:\temp\nestjs-starter-kit\node_modules\prettier\index.js:7515:23)
at coreFormat (D:\temp\nestjs-starter-kit\node_modules\prettier\index.js:8829:18)
at formatWithCursor2 (D:\temp\nestjs-starter-kit\node_modules\prettier\index.js:9021:18)
at D:\temp\nestjs-starter-kit\node_modules\prettier\index.js:38183:12
at Object.format (D:\temp\nestjs-starter-kit\node_modules\prettier\index.js:38197:12)
at D:\temp\nestjs-starter-kit\node_modules\typeorm-model-generator\dist\src\ModelGeneration.js:68:34
at Array.forEach () {
loc: { start: { line: 121, column: 69 } },
codeFrame: '\x1B[0m \x1B[90m 119 |\x1B[39m isCouponSystemActive\x1B[33m?\x1B[39m\x1B[33m:\x1B[39mboolean \x1B[33m|\x1B[39m \x1B[36mnull\x1B[39m\x1B[33m;\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 120 |\x1B[39m\x1B[0m\n' +
`\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 121 |\x1B[39m \x1B[33m@\x1B[39m\x1B[33mColumn\x1B[39m(\x1B[32m"varchar"\x1B[39m\x1B[33m,\x1B[39m{ name\x1B[33m:\x1B[39m\x1B[32m"tax_method"\x1B[39m\x1B[33m,\x1B[39mlength\x1B[33m:\x1B[39m\x1B[35m191\x1B[39m\x1B[33m,\x1B[39m\x1B[36mdefault\x1B[39m\x1B[33m:\x1B[39m () \x1B[33m=>\x1B[39m \x1B[32m"'{"\x1B[39mvat_tax_type\x1B[32m" : "\x1B[39m\x1B[32m","\x1B[39mtax_type\x1B[32m" : "\x1B[39m\x1B[32m" }'"\x1B[39m\x1B[33m,\x1B[39m })\x1B[0m\n` +
'\x1B[0m \x1B[90m     |\x1B[39m                                                                     \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 122 |\x1B[39m taxMethod\x1B[33m?\x1B[39m\x1B[33m:\x1B[39mstring\x1B[33m;\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 123 |\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 124 |\x1B[39m \x1B[33m@\x1B[39m\x1B[33mColumn\x1B[39m(\x1B[32m"timestamp"\x1B[39m\x1B[33m,\x1B[39m{ name\x1B[33m:\x1B[39m\x1B[32m"created_at"\x1B[39m\x1B[33m,\x1B[39mnullable\x1B[33m:\x1B[39m\x1B[36mtrue\x1B[39m })\x1B[0m'
}
[1:14:15 PM] Typeorm model classes created.
bash: -h: command not found
bash: -p: command not found
bash: -d: command not found
bash: -u: command not found
bash: -x: command not found
bash: -e: command not found
bash: -o: command not found
bash: --noConfig: command not found
bash: --ce: command not found
По этой причине:
  • Полная автоматическая генерация сущностей не работает так, как в prima (prisma db pull)
  • Переписывание сущностей вручную для сотен таблиц подвержено ошибкам и их сложно поддерживать


Подробнее здесь: https://stackoverflow.com/questions/798 ... -previousl
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «MySql»