npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

directus-auto-migrate

v0.3.2

Published

A CLI to automatically generate Directus migrations based on the changes in a real instance

Downloads

22

Readme

Directus Migrate

Motivation

There is no official way today to run migrations in Directus in a way to support automation between environments. The only way to do that is to create migrations using knex manually. Doing so however has a few drawbacks:

  • You have to write all migrations manually, instead of leveraging the Directus UI, which is much easier to use
  • Writing manual queries is very time-consuming
  • You have to know the Directus internals to understand what records to write in the system tables. Any eventual change to those internal tables done by the Directus team is hard to predict
  • All manual work is error-prone and can lead to data inconsistency

Solution

Given the above problem, here is the formula that this package implements to try to solve:

  • The first time the script is run, it generates a state file. This state file contains 2 main nodes - data and schema. Schema is extracted using knex-schema-inspector, while the data is queries from the system tables themselves
  • Everytime you run the script after that, it gets the same state and creates a comparison between the saved state and the current database's state

Usage

  • Run the script the first time to get your state
  • Do some changes in Directus UI
  • Run again to create a migration
  • Commit the state file in your SCM
npx directus-auto-migrate my-first-migration

Optional arguments:

  • envFile - path to the env file - the environment variables that are used are the same that Directus itself is using, trying to ensure a great level of compatibility. Defaults to .env
  • stateFile - path to the file to use as a state file. Defaults to directus-state.json
  • migrationsDir - path to the directory to write migrations in. Defaults to src/migrations
  • format (javascript/typescript) - whether to generate the migration as a JavaScript or a TypeScript file. Defaults to javascript
  • preview - whether to run the script to see the diff only, but without writing to the state file or creating the actual migration. Exception: if this is the first run of the script, the state file will be created. Defaults to false

Disclaimer

The solution is experimental and only tested with Postgres. Please always inspect the generated queries and verify that they correspond to the real changes being done.

It is recommended that after the migration is generated, you reset your database with that migration to ensure that the Directus app works as expected.

It is recommended to use Docker for easier database start and restart and to leverage the Directus migrations system