123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { DataTypes } from '@sequelize/core';
- import { expect } from 'chai';
- import { sequelize } from '../support';
- const queryInterface = sequelize.queryInterface;
- describe('QueryInterface#dropAllTables', () => {
- describe('Without schema', () => {
- beforeEach(async () => {
- await queryInterface.createTable('levels', {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- });
- await queryInterface.createTable('actors', {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- levelId: {
- type: DataTypes.INTEGER,
- allowNull: false,
- references: {
- table: 'levels',
- key: 'id',
- },
- },
- });
- });
- it('should drop all tables', async () => {
- await queryInterface.dropAllTables();
- const tables = await queryInterface.listTables();
- expect(tables).to.be.empty;
- });
- });
- if (sequelize.dialect.supports.schemas) {
- describe('With schema', () => {
- const schema = 'archive';
- beforeEach(async () => {
- await queryInterface.createSchema(schema);
- await queryInterface.createTable(
- {
- tableName: 'levels',
- schema,
- },
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- },
- );
- await queryInterface.createTable(
- {
- tableName: 'actors',
- schema,
- },
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- levelId: {
- type: DataTypes.INTEGER,
- allowNull: false,
- references: {
- table: {
- tableName: 'levels',
- schema,
- },
- key: 'id',
- },
- },
- },
- );
- });
- it('should drop a table', async () => {
- await queryInterface.dropAllTables();
- const tables = await queryInterface.listTables();
- expect(tables).to.be.empty;
- });
- });
- }
- });
|