### Fireway Project Setup and Testing Commands Source: https://github.com/dev-aces/fireway/blob/main/README.md These commands are used for setting up the project by installing dependencies, setting up the environment, and building/testing the project. They are essential for contributing to the Fireway project. ```bash $ npm install $ npm setup $ npm run build && npm run test ``` -------------------------------- ### Start Firebase Emulators Source: https://github.com/dev-aces/fireway/blob/main/README.md Start the Firebase local emulators, including the Firestore emulator, using the Firebase CLI. ```bash firebase emulators:start ``` -------------------------------- ### Install ts-node for TypeScript Source: https://github.com/dev-aces/fireway/blob/main/README.md Install ts-node as a development dependency if you are using TypeScript migrations. ```bash npm i ts-node ``` -------------------------------- ### TypeScript Migration Example Source: https://github.com/dev-aces/fireway/blob/main/README.md Basic migration script using TypeScript. Ensure the file is named in the format `v[semver]__[description].ts` and placed in the migration directory. ```typescript // ./migrations/v0.0.1__typescript_example.ts import { IMigrationFunctionsArguments } from '@dev-aces/fireway'; export async function migrate({ firestore }: IMigrationFunctionsArguments) { await firestore .collection('my_table') .doc('document_id') .set({ name: 'Fireway' }); } ``` -------------------------------- ### JavaScript Migration Example Source: https://github.com/dev-aces/fireway/blob/main/README.md Basic migration script using CommonJS JavaScript. Ensure the file is named in the format `v[semver]__[description].js` and placed in the migration directory. ```javascript // ./migrations/v0.0.1__javascript_example.js module.exports.migrate = async ({ firestore }) => { await firestore .collection('my_table') .doc('document_id') .set({ name: 'Fireway' }); }; ``` -------------------------------- ### Install Fireway NPM Package Source: https://github.com/dev-aces/fireway/blob/main/README.md Install the Fireway NPM package into your Firebase functions project using npm. ```bash npm i @dev-aces/fireway ``` -------------------------------- ### Fireway Migration Result Schema Source: https://github.com/dev-aces/fireway/blob/main/README.md Example structure of a migration result stored in the 'fireway' collection in Firestore. This includes details about the script execution and success status. ```javascript // fireway/v0.0.1__typescript_example { installed_rank: 3, // 0-based sequence checksum: 'fdfe6a55a7c97a4346cb59871b4ce97c', description: 'typescript_example', execution_time: 1221, installed_by: 'system_user_name', installed_on: Timestamp(), script: 'v0.0.1__typescript_example.ts', type: 'ts', version: '0.0.1', success: true } ``` -------------------------------- ### Run JavaScript Migrations Locally Source: https://github.com/dev-aces/fireway/blob/main/README.md Execute JavaScript migrations locally by setting environment variables for the project ID and Firestore emulator host. ```bash GCLOUD_PROJECT=project-id FIRESTORE_EMULATOR_HOST=localhost:8080 fireway migrate ``` -------------------------------- ### Run TypeScript Migrations Locally Source: https://github.com/dev-aces/fireway/blob/main/README.md Execute TypeScript migrations locally by setting environment variables for the project ID and Firestore emulator host, and using ts-node. ```bash GCLOUD_PROJECT=project-id FIRESTORE_EMULATOR_HOST=localhost:8080 fireway --require="ts-node/register" migrate ``` -------------------------------- ### Fireway CLI Migrate Command Usage Source: https://github.com/dev-aces/fireway/blob/main/README.md This shows the basic usage of the `fireway migrate` command and its available options. It's used for migrating database schemas to the latest version. ```bash Usage $ fireway migrate [options] Available Commands migrate Migrates schema to the latest version For more info, run any command with the `--help` flag $ fireway migrate --help Options --path Path to migration files (default "./migrations") --collection Firebase collection name for migration results (default "fireway") --require Requires a module before executing, example with TypeScript compiler: fireway migrate --require="ts-node/register" --dryRun Simulates changes --logLevel Log level, options: debug, log, warn, error (default "log") -v, --version Displays current version -h, --help Displays this message ``` -------------------------------- ### Firebase Firestore Emulator Configuration Source: https://github.com/dev-aces/fireway/blob/main/README.md Configure the Firestore emulator in your `firebase.json` file to enable local testing of migration scripts. ```json { "emulators": { "firestore": { "port": 8080 } } } ``` -------------------------------- ### GitHub Actions Workflow for Firebase Deployment Source: https://github.com/dev-aces/fireway/blob/main/README.md This snippet shows a GitHub Actions workflow for deploying Firebase functions and running migrations. It uses `google-github-actions/auth@v1` to authenticate with Google Cloud using a service account JSON key stored as a secret. ```yaml jobs: build_and_deploy: runs-on: ubuntu-latest name: Dev workflow steps: - uses: actions/checkout@v3 - name: 'NPP install and build steps' run: | echo "your scripts" - name: 'Authenticate to Google Cloud' uses: 'google-github-actions/auth@v1' with: credentials_json: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON_DEV }}' create_credentials_file: true cleanup_credentials: true - name: Deploy functions and run migrations run: | npm run migrate firebase deploy --only functions ``` -------------------------------- ### NPM Script for Fireway Migration Source: https://github.com/dev-aces/fireway/blob/main/README.md This npm script is used to run Fireway migrations, specifically configured to use `ts-node/register` for TypeScript migration files. ```json "migrate": "fireway migrate --require=\"ts-node/register\"" ``` -------------------------------- ### Extended TypeScript Migration with Auth and FieldValue Source: https://github.com/dev-aces/fireway/blob/main/README.md An advanced migration script demonstrating the use of Firebase Auth and Firestore's FieldValue for operations like deleting fields and setting server timestamps. Requires Firebase Admin SDK initialization. ```typescript // ./migrations/v0.2.0__typescript_extended_example.ts import { IMigrationFunctionsArguments } from '@dev-aces/fireway'; import { getAuth } from 'firebase-admin/auth'; import { FieldValue } from 'firebase-admin/firestore'; export async function migrate({ firestore, app, }: IMigrationFunctionsArguments) { // Auth example const firebaseAuth = getAuth(app); const email = 'test-user@test.com'; // search user identity const user = await firebaseAuth.getUserByEmail(email); if (!user) { await firebaseAuth.createUser({ email: email, emailVerified: true, disabled: false, }); } // FieldValue example await firestore.collection('table').doc('123').ref.update({ obsoleteField: FieldValue.delete(), date: FieldValue.serverTimestamp(), }); } ``` -------------------------------- ### tsconfig.json for ts-node Source: https://github.com/dev-aces/fireway/blob/main/README.md Configure ts-node within your `tsconfig.json` file to enable transpilation on the fly for CommonJS modules. ```json { "ts-node": { "transpileOnly": true, "compilerOptions": { "module": "commonjs" } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.