Migration script is empty

default discord avatar
thetimewalker
last month
8

Hey there, while trying to migrate, I wanted to use the easy "one-liner" to create a migration ts file that would automatically add the

latest: true

flag.


However, when running that, the up and down scripts of the ts file are just empty. Am I missing something? The payload-config.ts location should be correct and I do have one collection that has

drafts: true

set.



Collection:


export const Pages: CollectionConfig = {
  slug: "pages",
  admin: {
    useAsTitle: "fullTitle",
    preview: (doc) => formatPreviewURL("pages", doc),
    defaultColumns: ["fullTitle", "slug", "createdAt", "updatedAt"],
  },
  versions: {
    drafts: true,
  },
  access: {
    read: isAuthorOrPublic,
    readVersions: isAuthor,
    update: isAuthor,
    delete: isAuthor,
  },
  hooks: {
    afterChange: [
      ...
    ],
  },
  fields: [
    ...
  ],
};
  • default discord avatar
    stangnes
    last month

    I cant even run the script: "Unknown script "migrate:create".

  • default discord avatar
    mmthd
    last month

    add it in the package.json

    "payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload"

    and adjust the path for your payload config & dont forget to adjust your collections, fields etc. with the new Editor property

    https://github.com/payloadcms/payload/releases/tag/v2.0.0

    :



    from:


    const myRichTextField: Field = {
      name: "content",
      type: "richText",
      admin: {
        elements: [
          "h1",
          "link",
          // etc
        ],
      },
    };


    to:


    import { slateEditor } from "@payloadcms/richtext-slate";
    
    const myRichTextField: Field = {
      name: "content",
      type: "richText",
      editor: slateEditor({
        // Move the admin property as shown below
        admin: {
          elements: [
            "h1",
            "link",
            // etc
          ],
        },
      }),
    };


    Same here: By running

    npm run payload migrate:create --file @payloadcms/db-mongodb/versions-v1-v2

    payload creates currently a empty migration file with the main up/down functions:



    import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-mongodb'
    
    export async function up({ payload }: MigrateUpArgs): Promise<void> {
      // Migration code
    }
    
    export async function down({ payload }: MigrateDownArgs): Promise<void> {
      // Migration code
    }


    Payload Version:

    2.0.3
  • default discord avatar
    <Clement/>
    last month

    remove the "run" of command ?

  • default discord avatar
    mmthd
    last month

    I have copy the script from the node_modules & adjust it a little bit. This workaround is working for me:



    replace the content of your

    migrations/<timestamp>-_payloadcms_db_mongodb_versions_v1_v2.ts

    with the content of the migration.ts file & run

    npm run payload migrate
  • default discord avatar
    stangnes
    last month

    Thanks! I discovered that my project was not actually updated to version 2 due to incompatible plugins (fixed via force update). I am using the website template as a base which is not updated to version 2 on Github. Tried to clone a fresh version and do the update to version 2, but I have not managed to get it to work yet. I will test your workaround when I get the time to try again. For now I keep running version 1.

  • default discord avatar
    mvdve
    last month
  • discord user avatar
    denolfe
    Payload Team
    last month

    It looks like there are differences in how each package manager finds the predefined migration that need to be accounted for.



    The current workaround is to copy the contents of this file into your migration:

    https://github.com/payloadcms/payload/blob/main/packages/db-mongodb/predefinedMigrations/versions-v1-v2.js


    Will update the above issue as well

  • default discord avatar
    thetimewalker
    last month

    Thanks for the answers! I have quickly used yarn to create and run the migration and that one worked well. Strange why this works but npm doesn't, especially since the v1 -> v2 migration guide specifically mentions using "npm run payload"

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.