Я пытаюсь создать миграцию, и я создаю миграцию с помощью migration:run
, но создается файл:
import {MigrationInterface, QueryRunner} from "typeorm";
export class puntoVenta1580678729214 implements MigrationInterface {
name = 'puntoVenta1580678729214'
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query("CREATE TABLE `consultas` (`id_consultas` int NOT NULL AUTO_INCREMENT, `Estado_Pedido` tinyint NOT NULL, PRIMARY KEY (`id_consultas`)) ENGINE=InnoDB", undefined);
await queryRunner.query("CREATE TABLE `facturas` (`id_facturas` int NOT NULL AUTO_INCREMENT, `Producto` varchar(255) NOT NULL, `Precio_Producto` decimal NOT NULL, `Total` decimal NOT NULL, `Usuario` varchar(255) NOT NULL, PRIMARY KEY (`id_facturas`)) ENGINE=InnoDB", undefined);
await queryRunner.query("CREATE TABLE `productos` (`id_productos` int NOT NULL AUTO_INCREMENT, `Nombre_Producto` varchar(250) NOT NULL, `Precio_Producto` decimal NOT NULL, `Cantidad` decimal NOT NULL, `Proveedor` varchar(250) NOT NULL, `Categoria` varchar(255) NOT NULL, PRIMARY KEY (`id_productos`)) ENGINE=InnoDB", undefined);
await queryRunner.query("CREATE TABLE `usuarios` (`id_usuarios` int NOT NULL AUTO_INCREMENT, `Nombre` varchar(250) NOT NULL, `Apellido` varchar(250) NOT NULL, `Clave` varchar(20) NOT NULL, `Direccion` varchar(250) NOT NULL, `contacto` int NOT NULL, PRIMARY KEY (`id_usuarios`)) ENGINE=InnoDB", undefined);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query("DROP TABLE `usuarios`", undefined);
await queryRunner.query("DROP TABLE `productos`", undefined);
await queryRunner.query("DROP TABLE `facturas`", undefined);
await queryRunner.query("DROP TABLE `consultas`", undefined);
}
}
, и я хочу создать что-то вроде следующего. Кто-нибудь знает проблему?
import {MigrationInterface, QueryRunner, Table, TableIndex, TableColumn, TableForeignKey } from "typeorm";
export class QuestionRefactoringTIMESTAMP implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.createTable(new Table({
name: "question",
columns: [
{
name: "id",
type: "int",
isPrimary: true
},
{
name: "name",
type: "varchar",
}
]
}), true)
await queryRunner.createIndex("question", new TableIndex({
name: "IDX_QUESTION_NAME",
columnNames: ["name"]
}));
await queryRunner.createTable(new Table({
name: "answer",
columns: [
{
name: "id",
type: "int",
isPrimary: true
},
{
name: "name",
type: "varchar",
}
]
}), true);
Как я могу ее создать?