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

Fix Durable Object Migrator #4058

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

austinm911
Copy link

@austinm911 austinm911 commented Feb 3, 2025

Ran into an error where the durable object function was not parsing the migrations.json file produced

export class DrizzleDurableObject extends DurableObject {
	storage: DurableObjectStorage
	db: DrizzleSqliteDODatabase<typeof schema>

	constructor(ctx: DurableObjectState, env: Env) {
		super(ctx, env)
		this.storage = ctx.storage
		this.db = drizzle(this.storage, { logger: true })
		ctx.blockConcurrencyWhile(async () => {
			console.log('Migrations object:', JSON.stringify(migrations, null, 2))

			await migrate(this.db, migrations)
		})
	}
}
Migrations object: { 
  "journal": {
    "entries": [
      {
        "idx": 0,
        "version": "6",
        "when": 1738537506661,
        "tag": "0000_open_crystal",
        "breakpoints": true
      }
    ]
  },
  "migrations": {
    "0000_open_crystal": "CREATE TABLE `messages` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`content` text NOT NULL\n);\n--> statement-breakpoint\nCREATE TABLE `users` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`name` text NOT NULL\n);\n"
  }
}
Entering migrate function
Migration config: {
  journal: { entries: [ [Object] ] },
  migrations: {
    '0000_open_crystal': 'CREATE TABLE `messages` (\n' +
      '\t`id` text PRIMARY KEY NOT NULL,\n' +
      '\t`content` text NOT NULL\n' +
      ');\n' +
      '--> statement-breakpoint\n' +
      'CREATE TABLE `users` (\n' +
      '\t`id` text PRIMARY KEY NOT NULL,\n' +
      '\t`name` text NOT NULL\n' +
      ');\n'
  }
}
Entering readMigrationFiles
Journal: {
  entries: [
    {
      idx: 0,
      version: '6',
      when: 1738537506661,
      tag: '0000_open_crystal',
      breakpoints: true
    }
  ]
}
Migrations: {
  '0000_open_crystal': 'CREATE TABLE `messages` (\n' +
    '\t`id` text PRIMARY KEY NOT NULL,\n' +
    '\t`content` text NOT NULL\n' +
    ');\n' +
    '--> statement-breakpoint\n' +
    'CREATE TABLE `users` (\n' +
    '\t`id` text PRIMARY KEY NOT NULL,\n' +
    '\t`name` text NOT NULL\n' +
    ');\n'
}
Processing journal entry: {
  idx: 0,
  version: '6',
  when: 1738537506661,
  tag: '0000_open_crystal',
  breakpoints: true
}
Migration key: m0000
 [ERROR] Error: Missing migration for key: m0000


 [ERROR] Uncaught (in promise) Error: Missing migration: 0000_open_crystal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant