Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSCCE for #16430 #260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions src/sscce-sequelize-6.ts

This file was deleted.

40 changes: 27 additions & 13 deletions src/sscce-sequelize-7.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<InferAttributes<Member>, InferCreationAttributes<Member>> {
@Attribute(DataTypes.INTEGER)
declare userId: number;

@Attribute(DataTypes.INTEGER)
declare treeId: number;
}

@Table({ timestamps: false })
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@HasMany(() => Member, "userId")
declare members?: NonAttribute<Member[]>;
}

@Table({ timestamps: false })
class Tree extends Model<InferAttributes<Tree>, InferCreationAttributes<Tree>> {
@HasMany(() => Member, "treeId")
declare members?: NonAttribute<Member[]>;
}

// 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: {
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"compilerOptions": {
"target": "es2021",
"module": "CommonJS",
"moduleResolution": "Node",
"moduleResolution": "nodenext",
"experimentalDecorators": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"newLine": "lf",
Expand Down
Loading