@ronin/cli
Advanced tools
Comparing version 0.2.16-leo-ron-1071-experimental-59 to 0.2.16-leo-ron-1071-experimental-60
@@ -95,3 +95,3 @@ #!/usr/bin/env bun | ||
// package.json | ||
var version = "0.2.16-leo-ron-1071-experimental-59"; | ||
var version = "0.2.16-leo-ron-1071-experimental-60"; | ||
@@ -864,6 +864,8 @@ // src/utils/spinner.ts | ||
import { Transaction as Transaction2 } from "@ronin/compiler"; | ||
var getModels = async (db, token, spaceId, isProduction) => { | ||
var getModels = async (db, token, spaceId, isLocal = true) => { | ||
const transaction = new Transaction2([{ get: { models: null } }]); | ||
let rawResults; | ||
if (isProduction) { | ||
if (isLocal) { | ||
rawResults = (await db.query(transaction.statements)).map((r) => r.rows); | ||
} else { | ||
try { | ||
@@ -889,4 +891,2 @@ const nativeQueries = transaction.statements.map((statement) => ({ | ||
} | ||
} else { | ||
rawResults = (await db.query(transaction.statements)).map((r) => r.rows); | ||
} | ||
@@ -1145,3 +1145,3 @@ const results = transaction.formatResults(rawResults, false); | ||
apply: { type: "boolean", short: "a", default: false }, | ||
prod: { type: "boolean", short: "p", default: false } | ||
local: { type: "boolean", short: "l", default: false } | ||
}; | ||
@@ -1170,22 +1170,22 @@ async function main(appToken, sessionToken, flags2, positionals2) { | ||
var applyMigrationStatements = async (appTokenOrSessionToken, flags2, db, statements, slug) => { | ||
if (flags2.prod) { | ||
spinner.info("Applying migration to production database"); | ||
await fetch(`https://data.ronin.co/?data-selector=${slug}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${appTokenOrSessionToken}` | ||
}, | ||
body: JSON.stringify({ | ||
nativeQueries: statements.map((query) => ({ | ||
query: query.statement, | ||
mode: "write" | ||
})) | ||
}) | ||
}); | ||
if (flags2.local) { | ||
spinner.info("Applying migration to local database"); | ||
await db.query(statements.map(({ statement }) => statement)); | ||
fs9.writeFileSync(".ronin/db.sqlite", await db.getContents()); | ||
return; | ||
} | ||
spinner.info("Applying migration to local database"); | ||
await db.query(statements.map(({ statement }) => statement)); | ||
fs9.writeFileSync(".ronin/db.sqlite", await db.getContents()); | ||
spinner.info("Applying migration to production database"); | ||
await fetch(`https://data.ronin.co/?data-selector=${slug}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${appTokenOrSessionToken}` | ||
}, | ||
body: JSON.stringify({ | ||
nativeQueries: statements.map((query) => ({ | ||
query: query.statement, | ||
mode: "write" | ||
})) | ||
}) | ||
}); | ||
}; | ||
@@ -1201,3 +1201,3 @@ var create = async (appToken, sessionToken, flags2) => { | ||
const [existingModels, definedModels] = await Promise.all([ | ||
getModels(db, appToken ?? sessionToken, slug, flags2.prod), | ||
getModels(db, appToken ?? sessionToken, slug, flags2.local), | ||
getModelDefinitions() | ||
@@ -1277,3 +1277,3 @@ ]); | ||
slug, | ||
flags2.prod | ||
flags2.local | ||
); | ||
@@ -1280,0 +1280,0 @@ const protocol = await new Protocol().load(migrationFilePath); |
{ | ||
"name": "@ronin/cli", | ||
"version": "0.2.16-leo-ron-1071-experimental-59", | ||
"version": "0.2.16-leo-ron-1071-experimental-60", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "The command-line interface for RONIN.", |
63388