This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
generated from reactioncommerce/api-plugin-example
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from reactioncommerce/fix-28-mohan-multishop-d…
…up-tag-create fix: allow different shops to have same tag name
- Loading branch information
Showing
8 changed files
with
22,222 additions
and
100 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import register from "./src/index.js"; | ||
|
||
export { default as migrations } from "./migrations/index.js"; | ||
|
||
export default register; |
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,20 @@ | ||
/** | ||
* @summary remove index slug_1 from tags | ||
* @param {Object} args - the arguments | ||
* @param {Object} args.db - the DB client | ||
* @param {Function} args.progress - a function to set the progress of the operation | ||
* @returns {undefined} | ||
*/ | ||
async function up({ db, progress }) { | ||
progress(0); | ||
|
||
const index = "slug_1"; | ||
await db.collection("Tags").dropIndex(index); | ||
|
||
progress(100); | ||
} | ||
|
||
export default { | ||
down: "unnecessary", | ||
up | ||
}; |
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,13 @@ | ||
import { migrationsNamespace } from "./migrationsNamespace.js"; | ||
import migration2 from "./2.js"; | ||
|
||
export default { | ||
tracks: [ | ||
{ | ||
namespace: migrationsNamespace, | ||
migrations: { | ||
2: migration2 | ||
} | ||
} | ||
] | ||
}; |
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 @@ | ||
export const migrationsNamespace = "tags"; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
import doesDatabaseVersionMatch from "@reactioncommerce/db-version-check"; | ||
import { migrationsNamespace } from "../migrations/migrationsNamespace.js"; | ||
|
||
const expectedVersion = 2; | ||
|
||
/** | ||
* @summary Called before startup | ||
* @param {Object} context Startup context | ||
* @returns {undefined} | ||
*/ | ||
export default async function preStartup(context) { | ||
const setToExpectedIfMissing = async () => { | ||
const anyAccount = await context.collections.Accounts.findOne(); | ||
const anyGroup = await context.collections.Groups.findOne(); | ||
return !anyAccount && !anyGroup; | ||
}; | ||
|
||
const ok = await doesDatabaseVersionMatch({ | ||
// `db` is a Db instance from the `mongodb` NPM package, | ||
// such as what is returned when you do `client.db()` | ||
db: context.app.db, | ||
// These must match one of the namespaces and versions | ||
// your package exports in the `migrations` named export | ||
expectedVersion, | ||
namespace: migrationsNamespace, | ||
setToExpectedIfMissing | ||
}); | ||
|
||
if (!ok) { | ||
throw new Error(`Database needs migrating. The "${migrationsNamespace}" namespace must be at version ${expectedVersion}. See docs for more information on migrations: https://github.com/reactioncommerce/api-migrations`); | ||
} | ||
} |