Feat/migrations cli (#2940)
* feat: migrate cli call db adapter * feat: mongoose adapter migrate:create * feat: implement migrate command * feat: use mongooseAdapter in test config * feat: use filename as migration name * feat: intelligently execute migrations, status table * feat: implement migrate:down * feat: implement migrate:reset * feat: implement migrate:refresh * feat: move common adapter operations to database/migrations dir * feat: delete migrations instead of storing ran property * feat: createMigration cleanup * feat: clean up logging and add duration to output * chore: export type, handle graphQL false * chore: simplify getting latest batch number * chore: remove existing migration logging noise * feat: remove adapter export from top level * chore: fix some db types
This commit is contained in:
52
test/migrations-cli/config.ts
Normal file
52
test/migrations-cli/config.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import path from 'path';
|
||||
import { buildConfig } from '../buildConfig';
|
||||
import { CollectionConfig } from '../../types';
|
||||
import { mongooseAdapter } from '../../src/mongoose';
|
||||
import payload from '../../src';
|
||||
|
||||
const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
auth: true,
|
||||
fields: [
|
||||
{
|
||||
name: 'custom',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'checkbox',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// // @ts-expect-error partial
|
||||
// const mockAdapter: DatabaseAdapter = {
|
||||
// // payload: undefined,
|
||||
// migrationDir: path.resolve(__dirname, '.migrations'),
|
||||
// migrateStatus: async () => console.log('TODO: migrateStatus not implemented.'),
|
||||
// createMigration: async (): Promise<void> =>
|
||||
// console.log('TODO: createMigration not implemented.'),
|
||||
// migrate: async (): Promise<void> => console.log('TODO: migrate not implemented.'),
|
||||
// migrateDown: async (): Promise<void> =>
|
||||
// console.log('TODO: migrateDown not implemented.'),
|
||||
// migrateRefresh: async (): Promise<void> =>
|
||||
// console.log('TODO: migrateRefresh not implemented.'),
|
||||
// migrateReset: async (): Promise<void> =>
|
||||
// console.log('TODO: migrateReset not implemented.'),
|
||||
// migrateFresh: async (): Promise<void> =>
|
||||
// console.log('TODO: migrateFresh not implemented.'),
|
||||
// };
|
||||
|
||||
export default buildConfig({
|
||||
serverURL: 'http://localhost:3000',
|
||||
admin: {
|
||||
user: Users.slug,
|
||||
},
|
||||
collections: [Users],
|
||||
typescript: {
|
||||
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
||||
},
|
||||
db: mongooseAdapter({ payload, url: 'mongodb://localhost:27017/migrations-cli-test' }),
|
||||
});
|
||||
48
test/migrations-cli/payload-types.ts
Normal file
48
test/migrations-cli/payload-types.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/* tslint:disable */
|
||||
/**
|
||||
* This file was automatically generated by Payload CMS.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
|
||||
* and re-run `payload generate:types` to regenerate this file.
|
||||
*/
|
||||
|
||||
export interface Config {
|
||||
collections: {
|
||||
users: User;
|
||||
'payload-preferences': PayloadPreference;
|
||||
};
|
||||
globals: {};
|
||||
}
|
||||
export interface User {
|
||||
id: string;
|
||||
custom?: string;
|
||||
checkbox?: boolean;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
email: string;
|
||||
resetPasswordToken?: string;
|
||||
resetPasswordExpiration?: string;
|
||||
salt?: string;
|
||||
hash?: string;
|
||||
loginAttempts?: number;
|
||||
lockUntil?: string;
|
||||
password?: string;
|
||||
}
|
||||
export interface PayloadPreference {
|
||||
id: string;
|
||||
user: {
|
||||
value: string | User;
|
||||
relationTo: 'users';
|
||||
};
|
||||
key?: string;
|
||||
value?:
|
||||
| {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
| unknown[]
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
Reference in New Issue
Block a user