diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts deleted file mode 100644 index c90761b96..000000000 --- a/src/sscce-sequelize-6.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { DataTypes, Model } from 'sequelize'; -import { createSequelize6Instance } from '../setup/create-sequelize-instance'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -// if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); - -// You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 - -// Your SSCCE goes inside this function. -export async function run() { - // This function should be used instead of `new Sequelize()`. - // It applies the config for your SSCCE to work on CI. - const sequelize = createSequelize6Instance({ - logQueryParameters: true, - benchmark: true, - define: { - // For less clutter in the SSCCE - timestamps: false, - }, - }); - - class Foo extends Model {} - - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); - - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; - - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); -} diff --git a/src/sscce-sequelize-7.ts b/src/sscce-sequelize-7.ts index 861b9fdea..99dc8db8f 100644 --- a/src/sscce-sequelize-7.ts +++ b/src/sscce-sequelize-7.ts @@ -1,4 +1,5 @@ -import { DataTypes, Model } from '@sequelize/core'; +import { DataTypes, Model, InferAttributes, InferCreationAttributes, NonAttribute } from '@sequelize/core'; +import { HasMany, Attribute, Table, PrimaryKey } from "@sequelize/core/decorators-legacy"; import { createSequelize7Instance } from '../setup/create-sequelize-instance'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -10,9 +11,31 @@ export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', // Your SSCCE goes inside this function. export async function run() { + @Table({ timestamps: false }) + class Member extends Model, InferCreationAttributes> { + @Attribute(DataTypes.INTEGER) + declare userId: number; + + @Attribute(DataTypes.INTEGER) + declare treeId: number; + } + + @Table({ timestamps: false }) + class User extends Model, InferCreationAttributes> { + @HasMany(() => Member, "userId") + declare members?: NonAttribute; + } + + @Table({ timestamps: false }) + class Tree extends Model, InferCreationAttributes> { + @HasMany(() => Member, "treeId") + declare members?: NonAttribute; + } + // This function should be used instead of `new Sequelize()`. // It applies the config for your SSCCE to work on CI. const sequelize = createSequelize7Instance({ + models: [Member, User, Tree], logQueryParameters: true, benchmark: true, define: { @@ -21,21 +44,12 @@ export async function run() { }, }); - class Foo extends Model {} - - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); // You can use sinon and chai assertions directly in your SSCCE. + await sequelize.sync({ force: true }); + const spy = sinon.spy(); sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); + await sequelize.sync({ alter: true }); expect(spy).to.have.been.called; - - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); } diff --git a/tsconfig.json b/tsconfig.json index b17064f0e..74d935c68 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "compilerOptions": { "target": "es2021", "module": "CommonJS", - "moduleResolution": "Node", + "moduleResolution": "nodenext", + "experimentalDecorators": true, "esModuleInterop": true, "resolveJsonModule": true, "newLine": "lf",