Repository: sequelize/sequelize
File: packages/core/test/unit/query-generator/create-table-query.test.ts (TypeScript)

Code before:
      ibmi: `BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42710' BEGIN END; CREATE TABLE "myTable" ("myColumn" INTEGER(5) UNSIGNED); END`,
    });
  });

  it('produces a query to create a table with integer with references', () => {
    expectsql(queryGenerator.createTableQuery('myTable', { myColumn: 'INTEGER REFERENCES "Bar" ("id")' }), {
      default: 'CREATE TABLE IF NOT EXISTS [myTable] ([myColumn] INTEGER REFERENCES "Bar" ("id"));',
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` INTEGER, FOREIGN KEY (`myColumn`) REFERENCES "Bar" ("id")) ENGINE=InnoDB;',
      mssql: `IF OBJECT_ID(N'[myTable]', 'U') IS NULL CREATE TABLE [myTable] ([myColumn] INTEGER, FOREIGN KEY ([myColumn]) REFERENCES "Bar" ("id"));`,
      'snowflake db2': 'CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" INTEGER, FOREIGN KEY ("myColumn") REFERENCES "Bar" ("id"));',
      ibmi: `BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42710' BEGIN END; CREATE TABLE "myTable" ("myColumn" INTEGER REFERENCES "Bar" ("id")); END`,
    });
  });

  it('supports the engine option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { engine: 'MyISAM' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['engine']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=MyISAM;',
    });
  });

  it('supports the charset option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { charset: 'utf8mb4' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['charset']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;',
      snowflake: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['charset']),
    });
  });

  it('supports the collate option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { collate: 'en_US.UTF-8' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['collate']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB COLLATE en_US.UTF-8;',
      snowflake: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['collate']),
    });
  });

  it('supports the rowFormat option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { rowFormat: 'default' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['rowFormat']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB ROW_FORMAT=default;',
      snowflake: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['rowFormat']),
    });
  });

  it('supports the comment option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { comment: 'Foo' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['comment']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB COMMENT \'Foo\';',
      postgres: `CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" DATE); COMMENT ON TABLE "myTable" IS 'Foo';`,
      snowflake: `CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" DATE) COMMENT 'Foo';`,

Review comment (refactor):
You can remove this assertion, it will be done as part of default

Code after:
      ibmi: `BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42710' BEGIN END; CREATE TABLE "myTable" ("myColumn" INTEGER(5) UNSIGNED); END`,
    });
  });

  it('produces a query to create a table with integer with references', () => {
    expectsql(queryGenerator.createTableQuery('myTable', { myColumn: 'INTEGER REFERENCES "Bar" ("id")' }), {
      default: 'CREATE TABLE IF NOT EXISTS [myTable] ([myColumn] INTEGER REFERENCES "Bar" ("id"));',
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` INTEGER, FOREIGN KEY (`myColumn`) REFERENCES "Bar" ("id")) ENGINE=InnoDB;',
      mssql: `IF OBJECT_ID(N'[myTable]', 'U') IS NULL CREATE TABLE [myTable] ([myColumn] INTEGER, FOREIGN KEY ([myColumn]) REFERENCES "Bar" ("id"));`,
      'snowflake db2': 'CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" INTEGER, FOREIGN KEY ("myColumn") REFERENCES "Bar" ("id"));',
      ibmi: `BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42710' BEGIN END; CREATE TABLE "myTable" ("myColumn" INTEGER REFERENCES "Bar" ("id")); END`,
    });
  });

  it('supports the engine option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { engine: 'MyISAM' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['engine']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=MyISAM;',
    });
  });

  it('supports the charset option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { charset: 'utf8mb4' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['charset']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;',
    });
  });

  it('supports the collate option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { collate: 'en_US.UTF-8' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['collate']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB COLLATE en_US.UTF-8;',
    });
  });

  it('supports the rowFormat option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { rowFormat: 'default' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['rowFormat']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB ROW_FORMAT=default;',
    });
  });

  it('supports the comment option', () => {
    expectsql(() => queryGenerator.createTableQuery('myTable', { myColumn: 'DATE' }, { comment: 'Foo' }), {
      default: buildInvalidOptionReceivedError('createTableQuery', dialectName, ['comment']),
      'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `myTable` (`myColumn` DATE) ENGINE=InnoDB COMMENT \'Foo\';',
      postgres: `CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" DATE); COMMENT ON TABLE "myTable" IS 'Foo';`,
      snowflake: `CREATE TABLE IF NOT EXISTS "myTable" ("myColumn" DATE) COMMENT 'Foo';`,
    });
  });