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

@fwl/migration

v0.2.4

Published

Migration part of Fewlines Web Libraries

Downloads

18

Readme

= FWL Migration :toc: preamble

Disclaimer: this package is made for our internal usage and is only open source for convenience so we might not consider Pull Requests or Issues. Feel free to fork though.

This is part of the Fewlines Web Libraries packages.

It provides a migration tool using SQL files.

== Installation

[source, shell]

yarn add @fwl/migration

== Usage

migration is a database migration library written in TypeScript, which can be used as a CLI or imported as a npm package.

It will look into the migrations folder and execute each SQL queries, in the correct order. If one of the transaction fails, migration will keep track of the last successful query through a migration_schemas table, so you can safely rerun the migration process.

=== As a CLI

==== Config object

To run migration as a CLI, you can create a config.json with the following data structure:

[source, typescript]

{ "database": { "database": string; "password": string; "username": string; "host": string; "port": number; "ssl"?: boolean | { rejectUnauthorized: boolean, ca?: string; key?: string; cert?: string; } }, "migration": { "dirPath": string; "tableName"?: string } }

If you don't, the default config object will be used. The default config values can be overridden with various flags, listed in the following section.

You can then simply run one of those command, depending on your needs:

==== migration migrate

Run the database migration process. The following options can be passed to this command:

|=== | Flag name | Description

| configPath | Override the path to the configuration file (default: "./config.json").

| databaseURL | Override the database configuration, should be a valid PostgreSQL URL (setting this will override the configuration file).

| sslCaPath | Can be the relative or the absolute path to the file. Add the SSL CA to the config object, and set rejectUnauthorized to false.

| sslKeyPath | Can be the relative or the absolute path to the file. Add the SSL Key to the config object, and set rejectUnauthorized to false.

| sslCertPath | Can be the relative or the absolute path to the file. Add the SSL Cert to the config object, and set rejectUnauthorized to false.

| migrationsPath | Override the path to the migrations SQL files (setting this will override the configuration file).

| migrationsTable | Override the table name in which ran migrations are registered (setting this will override the configuration file). |===

==== migration dryRun

Run the migration process and rolls it back right away. The following options can be passed to this command:

|=== | Flag name | Description

| configPath | Override the path to the configuration file (default: "./config.json").

| databaseURL | Override the database configuration, should be a valid PostgreSQL URL (setting this will override the configuration file).

| sslCaPath | Can be the relative or the absolute path to the file. Add the SSL CA to the config object, and set rejectUnauthorized to false.

| sslKeyPath | Can be the relative or the absolute path to the file. Add the SSL Key to the config object, and set rejectUnauthorized to false.

| sslCertPath | Can be the relative or the absolute path to the file. Add the SSL Cert to the config object, and set rejectUnauthorized to false.

| migrationsPath | Override the path to the migrations SQL files (setting this will override the configuration file).

| migrationsTable | Override the table name in which ran migrations are registered, (setting this will override the configuration file). |===

==== migration create name_of_the_file`

Create a timestamped migration file in the path set up in config.json. The following options can be passed to this command:

|=== | Flag name | Description

| configPath | Override the path to the configuration file (default: "./config.json").

| migrationsPath | Override the path to the migrations SQL files (setting this will override the configuration file). |===

=== As a Package

If you need more customization and control over the migration process, you can implement your own logic by importing the package, which give you access to two functions.

==== runMigrations

You can give a config of runMigrationsConfig type as argument, or use the default settings by using the provided defaultConfig for the migrations folder and the database config:

[source, typescript]

import * as migration from "@fwl/migration"; import { defaultConfig as databaseDefaultConfig } from "@fwl/database";

migration.runMigrations({ database: databaseDefaultConfig, migration: migration.defaultConfig, });

==== createMigrationFile

The createMigrationFile takes the name of the file as an argument:

[source, typescript]

import * as migration from "@fwl/migration";

migration.createMigrationFile("name_of_the_file");

You can also use it through a custom npm script, and use the corresponding process.argv value as arguments.

[source, typescript]

import * as migration from "@fwl/migration"; import path from "path";

function createMigrationFile(): void { const [, , ...args] = process.argv; const dirPath = path.join(process.cwd(), "./relative/path");

if (args.length > 0) { if (args.length === 1) { migration.createMigrationFile(args[0], dirPath); } else { throw new Error("Provide only one file name at a time."); } } else { throw new Error("Provide the name_of_the_file."); } }

createMigrationFile();