UNPKG

@palmares/databases

Version:

Add support for working with databases with palmares framework

70 lines 4.57 kB
import type { EmptyOptionsOnGenerateFilesType } from './types'; import type { DatabaseAdapter } from '../../engine'; import type { DatabaseSettingsType, InitializedEngineInstancesType, InitializedModelsType, OptionalMakemigrationsArgsType } from '../../types'; import type { ActionToGenerateType } from '../actions/types'; import type { FoundMigrationsFileType } from '../types'; /** * Class used for creating migrations, right now we keep everything in a single file. But we might separate it after. * * The main and only method you are able to call is the factory method `.buildAndRun()`. So we will build the class * and generate the migrations automatically for the user. * * All of the migrations must pass through this class, even for empty migrations, if the user does not use this for * generating migrations errors might happen. */ export declare class MakeMigrations { #private; settings: DatabaseSettingsType; database: string; filteredMigrationsOfDatabase: FoundMigrationsFileType[]; optionalArgs: OptionalMakemigrationsArgsType; engine: DatabaseAdapter<any>; constructor(engine: DatabaseAdapter<any>, database: string, settings: DatabaseSettingsType, originalModels: InitializedModelsType[], stateModels: InitializedModelsType[], filteredMigrationsOfDatabase: FoundMigrationsFileType[], optionalArgs: OptionalMakemigrationsArgsType); /** * Adds the initialized models array to an object where the keys are the model name and the values are the * initialized model. We do this to both the original ones (defined in the application) and the models. * * @param originalModels - The models inside of the application, the ones defined in the models.(js/ts) file * or retrieved in the `getModels` method inside of the domain. * @param stateModels - The models built by the state, we run each migration in order and retrieve the state * of it, one after the other. */ modelsArrayToObjectByName(originalModels: InitializedModelsType[], stateModels: InitializedModelsType[]): void; /** * Method responsible for condensing the operations in a single file. For example, let's suppose we have two Domains: * `auth` and `posts`, on the `posts` domain we have the `Post` model and on the `auth` domain we have the `User` * model. So let's suppose we did 3 operations after the last migrations: * * 1. We've added a new field in 'Post' called `dateOfPost`. * 2. We've set in the 'Post' model, on the the existing field `description` as `allowBlank = true`. * 3. On the `User` model we've added a new `dateJoined` field. * * operations 1 and 2 are related to the model `Post` that is located in the `posts` domain. * The operation 3 is related to the model `User` that is located in the `auth` domain. * * This means that operations 1 and 2 must exist in a single file, and the operation 3 should exist in other. * THat's exactly what we do in this function we merge operations related to the same domain in a single file so we * don't need one file for each operation. * * @param operations - All of the operations that we need to run for this database. We will separate them to their * files inside of this method. * @param emptyOptions - (optional) - Those are the custom options if the value is an empty migration. An empty * migration is a migration file without any operations. This is preferred instead of creating the file by hand. * * @returns - Returns the last migration name. */ generateFiles(operations: ActionToGenerateType<any>[], emptyOptions?: EmptyOptionsOnGenerateFilesType): Promise<string>; /** * This is the main entrypoint for the `makemigrations` command. We run this function and the * side effects run in order so we are able to retrieve the operations that we need to do in the database * to match the changes that were made to the models. * * First we need to retrieve all of the operations, second we need to reorder those operations, and last but not least * we generate the file. * If the `makemigrations` has the `--empty` flag in it then we create an empty migration after every migration were * created. */ _run(): Promise<void>; static buildAndRun(settings: DatabaseSettingsType, migrations: FoundMigrationsFileType[], initializedEngineInstances: InitializedEngineInstancesType, optionalArgs: OptionalMakemigrationsArgsType): Promise<void>; } //# sourceMappingURL=index.d.ts.map