Skip to content

Commit

Permalink
Skip prefix on main script, to allow transition
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Aug 6, 2023
1 parent f53d5f0 commit 036f6c3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/advanced-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface UmzeptionDependency<T extends AnyUmzeptionContext = AnyUmzeptio
// The fully resolved internal definition
export interface UmzeptionDefinition<T extends AnyUmzeptionContext = AnyUmzeptionContext> extends UmzeptionDependency<T> {
name: string
noPrefix?: boolean
pluginDir: string
}

Expand Down
5 changes: 3 additions & 2 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function umzeptionLookup (options, context) {
glob: [],
installSchema: async () => {},
name: 'main',
noPrefix: true,
pluginDir: cwd,
...mainDefinitionExtras,
};
Expand All @@ -47,8 +48,8 @@ export async function umzeptionLookup (options, context) {
const definitions = [...dependencyDefinitions, mainDefinition];

const installations = definitions.map(definition => {
// ':' instead of '|' to differentiate against migrations
const name = definition.name + ':install';
// ':' instead of '|' to differentiate against migrations, and keep ':' on prefix less to avoid clash with file names
const name = (definition.noPrefix ? '' : definition.name) + ':install';

/** @type {import('umzug').RunnableMigration<T>} */
const result = {
Expand Down
13 changes: 10 additions & 3 deletions lib/resolve-migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ import { importAbsolutePath } from 'plugin-importer';

/**
* @template {import('./advanced-types.d.ts').AnyUmzeptionContext} T
* @param {Pick<import('./advanced-types.d.ts').UmzeptionDefinition<T>, 'glob' | 'name' | 'pluginDir'>} definition
* @param {Pick<import('./advanced-types.d.ts').UmzeptionDefinition<T>, 'glob' | 'name' | 'noPrefix' | 'pluginDir'>} definition
* @param {T} _context
* @param {boolean} [noop] - if set then the up/down migrations will have no operation
* @returns {Promise<import('umzug').RunnableMigration<T>[]>}
*/
export async function resolveMigrations ({ glob, name: definitionName, pluginDir }, _context, noop = false) {
export async function resolveMigrations (definition, _context, noop = false) {
const {
glob,
name: definitionName,
noPrefix,
pluginDir,
} = definition;

const files = await globby(glob, { cwd: pluginDir, absolute: true });

return Promise.all(files.map(async file => {
Expand All @@ -37,7 +44,7 @@ export async function resolveMigrations ({ glob, name: definitionName, pluginDir
throw new TypeError('Invalid migration, expected a "up" method');
}

const name = definitionName + '|' + path.basename(file);
const name = (noPrefix ? '' : definitionName + '|') + path.basename(file);

/** @type {import('umzug').RunnableMigration<T>} */
const result = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"clean": "run-p clean:*",
"prepare": "husky install",
"prepublishOnly": "run-s build",
"test:node": "c8 --reporter=lcov --reporter text node --test",
"test:node": "c8 --reporter=lcov --reporter text node --test test/*.spec.js",
"test-ci": "run-s test:*",
"test": "run-s check test:*"
},
Expand Down
4 changes: 2 additions & 2 deletions test/complex-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ describe('Complex Integration', () => {
'test-dependency:install',
'test-dependency-2:install',
'test-dependency-3:install',
'main:install',
':install',
'test-dependency|foo-01.js',
'test-dependency-2|bar-01.js',
'test-dependency-3|abc-01.js',
'main|foo-01.js',
'foo-01.js',
]);

assert.deepEqual(
Expand Down
14 changes: 7 additions & 7 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('Integration', () => {

assert.deepStrictEqual(executed, [
'test-dependency:install',
'main:install',
':install',
'test-dependency|foo-01.js',
'main|foo-01.js',
'foo-01.js',
]);

assert.deepEqual(
Expand Down Expand Up @@ -91,9 +91,9 @@ describe('Integration', () => {

assert.deepStrictEqual(executed, [
'test-dependency:install',
'main:install',
':install',
'test-dependency|foo-01.js',
'main|foo-01.js',
'foo-01.js',
]);

assert.deepEqual(
Expand Down Expand Up @@ -131,9 +131,9 @@ describe('Integration', () => {

assert.deepStrictEqual(executed, [
'test-dependency:install',
'main:install',
':install',
'test-dependency|foo-01.js',
'main|foo-01.js',
'foo-01.js',
]);

assert.deepEqual(
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Integration', () => {

assert.deepStrictEqual(executed, [
'test-dependency:install',
'main:install',
':install',
'test-dependency|foo-01.js',
]);

Expand Down
4 changes: 2 additions & 2 deletions test/pg-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('PG Integration', () => {
[
'INSERT INTO umzeption_migrations (name) VALUES ($1)',
[
'main:install',
':install',
],
],
[
Expand All @@ -96,7 +96,7 @@ describe('PG Integration', () => {
[
'INSERT INTO umzeption_migrations (name) VALUES ($1)',
[
'main|foo-01.js',
'foo-01.js',
],
],
]);
Expand Down

0 comments on commit 036f6c3

Please sign in to comment.