drop-all-tables.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { DataTypes } from '@sequelize/core';
  2. import { expect } from 'chai';
  3. import { sequelize } from '../support';
  4. const queryInterface = sequelize.queryInterface;
  5. describe('QueryInterface#dropAllTables', () => {
  6. describe('Without schema', () => {
  7. beforeEach(async () => {
  8. await queryInterface.createTable('levels', {
  9. id: {
  10. type: DataTypes.INTEGER,
  11. autoIncrement: true,
  12. primaryKey: true,
  13. },
  14. name: {
  15. type: DataTypes.STRING,
  16. allowNull: false,
  17. },
  18. });
  19. await queryInterface.createTable('actors', {
  20. id: {
  21. type: DataTypes.INTEGER,
  22. autoIncrement: true,
  23. primaryKey: true,
  24. },
  25. levelId: {
  26. type: DataTypes.INTEGER,
  27. allowNull: false,
  28. references: {
  29. table: 'levels',
  30. key: 'id',
  31. },
  32. },
  33. });
  34. });
  35. it('should drop all tables', async () => {
  36. await queryInterface.dropAllTables();
  37. const tables = await queryInterface.listTables();
  38. expect(tables).to.be.empty;
  39. });
  40. });
  41. if (sequelize.dialect.supports.schemas) {
  42. describe('With schema', () => {
  43. const schema = 'archive';
  44. beforeEach(async () => {
  45. await queryInterface.createSchema(schema);
  46. await queryInterface.createTable(
  47. {
  48. tableName: 'levels',
  49. schema,
  50. },
  51. {
  52. id: {
  53. type: DataTypes.INTEGER,
  54. autoIncrement: true,
  55. primaryKey: true,
  56. },
  57. name: {
  58. type: DataTypes.STRING,
  59. allowNull: false,
  60. },
  61. },
  62. );
  63. await queryInterface.createTable(
  64. {
  65. tableName: 'actors',
  66. schema,
  67. },
  68. {
  69. id: {
  70. type: DataTypes.INTEGER,
  71. autoIncrement: true,
  72. primaryKey: true,
  73. },
  74. levelId: {
  75. type: DataTypes.INTEGER,
  76. allowNull: false,
  77. references: {
  78. table: {
  79. tableName: 'levels',
  80. schema,
  81. },
  82. key: 'id',
  83. },
  84. },
  85. },
  86. );
  87. });
  88. it('should drop a table', async () => {
  89. await queryInterface.dropAllTables();
  90. const tables = await queryInterface.listTables();
  91. expect(tables).to.be.empty;
  92. });
  93. });
  94. }
  95. });