To create a database model named Todo
with attributes title
(string) and completed
(boolean), use the following command:
npx sequelize-cli model:generate --name Todo --attributes title:string,completed:boolean
After generating the model, update the file extensions to TypeScript:
- Rename the migration file
*-create-todo.js
to*-create-todo.ts
in themigration
directory. - Rename the model file
todo.js
totodo.ts
in themodels
directory.
Execute the migration command to apply changes to your database:
pnpm run db:migrate
# or
npm run db:migrate
- Ensure your
tsconfig.json
is configured correctly to compile TypeScript files. - Adjust Sequelize typings or configurations in TypeScript as per your project requirements.
To create a seeder named User
, run the following command:
npx sequelize-cli seed:generate --name demo-user
This will create a new file in the seeders
directory.
- Navigate to the
seeders
directory. - Rename the generated JavaScript file to a TypeScript file (change
.js
to.ts
). - Open the file and add the necessary data for seeding.