-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement(core): use typeorm migrations instead of auto-synchronize
This fixes concurrency issues on init (lock errors) and avoids any potential data loss during schema synchronization.
- Loading branch information
Showing
7 changed files
with
67 additions
and
23 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,14 @@ | ||
const { homedir } = require("os") | ||
const { resolve } = require("path") | ||
|
||
module.exports = { | ||
type: "better-sqlite3", | ||
database: resolve(homedir(), ".garden", "db"), | ||
entities: [ | ||
resolve(__dirname, "build", "src", "db", "entities", "*.js"), | ||
], | ||
cli: { | ||
entitiesDir: "build/src/db/entities", | ||
migrationsDir: "src/db/migrations", | ||
} | ||
} |
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
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
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
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,45 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { MigrationInterface, QueryRunner } from "typeorm-with-better-sqlite3" | ||
|
||
export class Init1599658427984 implements MigrationInterface { | ||
name = "Init1599658427984" | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE IF NOT EXISTS "client_auth_token" ("_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "_createdAt" datetime NOT NULL DEFAULT (datetime('now')), "_updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "_version" integer NOT NULL, "token" varchar NOT NULL)` | ||
) | ||
await queryRunner.query( | ||
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_3f2902720f10884e413933e582" ON "client_auth_token" ("token") ` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE IF NOT EXISTS "garden_process" ("_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "_createdAt" datetime NOT NULL DEFAULT (datetime('now')), "_updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "_version" integer NOT NULL, "pid" integer NOT NULL, "startedAt" datetime NOT NULL, "arguments" varchar NOT NULL, "sessionId" varchar, "projectRoot" varchar, "projectName" varchar, "environmentName" varchar, "namespace" varchar, "persistent" boolean NOT NULL DEFAULT (0), "serverHost" varchar, "serverAuthKey" varchar, "command" varchar)` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE IF NOT EXISTS "local_address" ("_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "_createdAt" datetime NOT NULL DEFAULT (datetime('now')), "_updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "_version" integer NOT NULL, "projectName" varchar NOT NULL, "moduleName" varchar NOT NULL, "serviceName" varchar NOT NULL, "hostname" varchar NOT NULL)` | ||
) | ||
await queryRunner.query( | ||
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_ccb1b3de9e2a1bd39c4619d516" ON "local_address" ("projectName", "moduleName", "serviceName", "hostname") ` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE IF NOT EXISTS "warning" ("_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "_createdAt" datetime NOT NULL DEFAULT (datetime('now')), "_updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "_version" integer NOT NULL, "key" varchar NOT NULL, "hidden" boolean NOT NULL)` | ||
) | ||
await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_e32e342758d4c83273d405698e" ON "warning" ("key") `) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "IDX_e32e342758d4c83273d405698e"`) | ||
await queryRunner.query(`DROP TABLE "warning"`) | ||
await queryRunner.query(`DROP INDEX "IDX_ccb1b3de9e2a1bd39c4619d516"`) | ||
await queryRunner.query(`DROP TABLE "local_address"`) | ||
await queryRunner.query(`DROP TABLE "garden_process"`) | ||
await queryRunner.query(`DROP INDEX "IDX_3f2902720f10884e413933e582"`) | ||
await queryRunner.query(`DROP TABLE "client_auth_token"`) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
# Migrations | ||
|
||
A migration needs to be created every time an entity is updated (columns added or modified). Do this by running the `create-migration` script with the name of the entity in question as a parameter: | ||
A migration needs to be created every time an entity is added or updated (columns added or modified). Do this by running the `migrations:generate` script with the name of the entity in question as a parameter, after you've made your changes to the entity (or entities) in question: | ||
|
||
```console | ||
yarn run create-migration -- SomeEntity | ||
yarn migration:generate SomeEntity | ||
``` | ||
|
||
You then need to explicitly import the migration and reference in the `migrations` array in `src/db/connection.ts`. | ||
|
||
This is not needed for _new_ entities, only after modifying an entity after it has been previously released and used. |
This file was deleted.
Oops, something went wrong.