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

firestore-migration

v1.0.9

Published

firestore migration command tool.

Downloads

13

Readme

npm version CircleCI

🎉firestore-migration🎉

firestore-migrationとは

これはfirestoreのdatabaseをmigrationするためのcomman lineツールです。

注意事項

現状、実装段階です。
ご利用する際はツールの挙動等を理解した上でご利用いただけますと幸いです。

仕組み[バージョンの管理について]

このツールを利用すると、初回に「migrations」というcollectionがrootに作成されます。
このcollectionでmigrationのバージョン管理を行っております。
collection内のdocumentIDとmigrationファイル「version_file名.json」のversionを比較し、versionが存在しなかった場合、対象のmigrationファイルを実行するというロジックで制作しています。

設定方法

環境変数

環境変数として以下を設定してください。

$FS_KEY: gcpのサービスアカウントkey(json)をBase64でdecodeした文字列

FS_KEYの作り方

ここを参考に、IAM>サービスアカウントからkeyを発行します。jsonのkeyファイルをダウンロードしたら、以下コマンドでBase64デコードを行います。

cat [jsonkeyファイルパス] | base64 -w 0

出力された文字列をFS_KEY環境変数に設定すればOKです。

インストール

npm or yarnで以下コマンドでinstallしてください。

npm install -g firestore-migration
or
yarn global add firestore-migration

使い方

fsmigrate -c [ファイル名]

このコマンドでmigrationを行うためのファイルを生成します。

fsmigrate -m [スクリプト格納フォルダパス]

migration -cで生成したファイルからmigrationを実施します。

ファイルの記述方法

Field Add

対象コレクションへのフィールドの追加を行う場合、以下のように記述します。

{
   "method": "ADD",
   "collection": "tests", // collection nameを記載
   "params": [
      {"name": "propA", "value": "propB"}, // name: フィールド名、value:設定する値
      {"name": "propC", "value": "propD"}
   ]
}

Field Delete

対象コレクションのフィールド削除を行う場合、以下のように記述します。

{
   "method": "DEL",
   "collection": "tests",
   "params": [
      {"name": "propA"},
      {"name": "propB"}
   ]
}

Field Modify

コレクション内の対象フィールドの内容を変更する場合、以下のように記述します。

{
   "method": "MOD",
   "collection": "tests",
   "params": [
      {"name": "propA", "if":"{propA} === 2 && {propC} === 'val2'","value": 1} // *1
   ]
}
[補足]
*1 if内では'{field名}'で現在格納されているfield内容を取得し、条件式を記述できます。trueの場合、value値を適用します。

Change Field Name

Field名の変更を実施する場合、以下のように記述します。

{
   "method": "CHANGE_FIELD_NAME",
   "collection": "user",
   "params": [
      {"name": "name", "to": "nickname"},
      {"name": "age", "to": "tosi"}
   ]
}