Skip to content

Commit b50431a

Browse files
authored
Add use case for handling database migrations with TypeScript (#2432)
1 parent c8816f2 commit b50431a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docusaurus/docs/dev-docs/database-migrations.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,45 @@ module.exports = {
9999
},
100100
};
101101
```
102+
103+
## Handling migrations with TypeScript code
104+
105+
By default Strapi looks for migration files in the source directory rather than the build directory when using TypeScript. This means that TypeScript migrations won't be found and executed properly unless you configure Strapi to look in the right place.
106+
107+
To enable TypeScript migrations in Strapi, you need to set the `useTypescriptMigrations` parameter to true in your database configuration. This setting tells Strapi to look for migrations in the build directory instead of the source directory.
108+
109+
Here's how to configure it in your database settings:
110+
111+
<Tabs groupId="js-ts">
112+
<TabItem value="js" label="JavaScript">
113+
114+
```jsx title="/config/database.js"
115+
module.exports = ({ env }) => ({
116+
connection: {
117+
// Your database connection settings
118+
},
119+
settings: {
120+
useTypescriptMigrations: true
121+
}
122+
});
123+
```
124+
125+
</TabItem>
126+
127+
<TabItem value="ts" label="TypeScript">
128+
129+
```tsx title="/config/database.ts"
130+
export default ({ env }) => ({
131+
connection: {
132+
// Your database connection settings
133+
},
134+
settings: {
135+
useTypescriptMigrations: true
136+
}
137+
});
138+
```
139+
140+
</TabItem>
141+
</Tabs>
142+
143+
Additionally, if you want to continue using existing JavaScript migrations alongside TypeScript migrations, you can set `allowJs: true` in your `tsconfig.json` file's compiler options, as mentioned in the [database configuration documentation](/dev-docs/configurations/database#settings-configuration-object).

0 commit comments

Comments
 (0)