-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migration helper scripts + docs (wip)
Resolves #211
- Loading branch information
Showing
7 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Migrations | ||
|
||
**Head Start uses DatoCMS migrations to develop CMS changes in isolation and ensure they can be reproduced.** | ||
|
||
|
||
Run | ||
|
||
```shell | ||
npm run cms:environment:create | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { execCommand } from './lib/exec-command'; | ||
import { datocmsEnvironment } from '../datocms-environment'; | ||
|
||
execCommand(`npx datocms migrations:run --destination=${datocmsEnvironment} --fast-fork`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { buildClient } from '@datocms/cma-client-node'; | ||
import dotenv from 'dotenv-safe'; | ||
import { execCommand } from './lib/exec-command'; | ||
import { datocmsEnvironment } from '../datocms-environment'; | ||
|
||
dotenv.config({ | ||
allowEmptyValues: Boolean(process.env.CI), | ||
}); | ||
|
||
const getPrimaryEnvironment = async () => { | ||
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN }); | ||
const environments = await client.environments.list(); | ||
return environments.find(env => env.meta.primary)?.id; | ||
}; | ||
|
||
async function run() { | ||
const sourceEnv = await getPrimaryEnvironment(); | ||
execCommand(`npx datocms environments:fork ${sourceEnv} ${datocmsEnvironment} --fast`); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { execCommand } from './lib/exec-command'; | ||
import { datocmsEnvironment } from '../datocms-environment'; | ||
|
||
execCommand(`npx datocms migrations:new --autogenerate=${datocmsEnvironment} ${datocmsEnvironment}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { execCommand } from './lib/exec-command'; | ||
import { datocmsEnvironment } from '../datocms-environment'; | ||
|
||
execCommand(`npx datocms environments:destroy ${datocmsEnvironment}`); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { exec } from 'node:child_process'; | ||
import { promisify } from 'node:util'; | ||
|
||
export const execCommand = async (command: string) => { | ||
const execAsync = promisify(exec); | ||
try { | ||
const { stdout } = await execAsync(command); | ||
console.log(stdout); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; |