Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose API for fetching which migrations have run #58

Closed
thdxr opened this issue Jan 24, 2022 · 4 comments
Closed

Expose API for fetching which migrations have run #58

thdxr opened this issue Jan 24, 2022 · 4 comments
Labels
api Related to library's API enhancement New feature or request

Comments

@thdxr
Copy link
Contributor

thdxr commented Jan 24, 2022

We're building a UI around running these migrations and need to know which migrations have already run without directly querying the migrations table

@koskimas
Copy link
Member

koskimas commented Jan 25, 2022

What do you think about adding a getState method for the Migrator that returns an object like this

interface MigrationState {
  // All migrations sorted by name.
  readonly migrations: ReadonlyArray<NamedMigration>

  // Index of the last executed migration. -1 if no migrations have been executed.
  readonly currentIndex: number
}

interface NamedMigration extends Migration {
  readonly name: string
}

interface Migration {
  up(db: Kysely<any>): Promise<void>
  down?(db: Kysely<any>): Promise<void>
}

Or do you need other information about the migrations, like the execution timestamp?

@thdxr
Copy link
Contributor Author

thdxr commented Jan 25, 2022

We'd probably like the timestamp but this works as a starting point

@koskimas
Copy link
Member

Maybe it's more future-proof to add a getMigrations method for Migrator that returns a list of these:

{
  name: string
  migration: Migration
  executedAt?: Date
}

executedAt would be undefined for unexecuted migrations. Or should we add an executed boolean as well?

@koskimas
Copy link
Member

@igalklebanov igalklebanov added enhancement New feature or request api Related to library's API labels Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants