summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fluffy-bobcats-arrive.md5
-rw-r--r--packages/db/src/core/cli/commands/push/index.ts4
-rw-r--r--packages/db/src/core/cli/migration-queries.ts5
-rw-r--r--packages/db/src/core/consts.ts2
-rw-r--r--packages/db/src/core/types.ts6
-rw-r--r--packages/db/test/unit/column-queries.test.js6
6 files changed, 16 insertions, 12 deletions
diff --git a/.changeset/fluffy-bobcats-arrive.md b/.changeset/fluffy-bobcats-arrive.md
new file mode 100644
index 000000000..199855362
--- /dev/null
+++ b/.changeset/fluffy-bobcats-arrive.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/db": patch
+---
+
+Rename `experimentalVersion` to `version`
diff --git a/packages/db/src/core/cli/commands/push/index.ts b/packages/db/src/core/cli/commands/push/index.ts
index 3e08de7b9..1c993e9a7 100644
--- a/packages/db/src/core/cli/commands/push/index.ts
+++ b/packages/db/src/core/cli/commands/push/index.ts
@@ -1,5 +1,4 @@
import type { AstroConfig } from 'astro';
-import { red } from 'kleur/colors';
import type { Arguments } from 'yargs-parser';
import { getManagedAppTokenOrExit } from '../../../tokens.js';
import { type DBConfig, type DBSnapshot } from '../../../types.js';
@@ -11,6 +10,7 @@ import {
getMigrationQueries,
getProductionCurrentSnapshot,
} from '../../migration-queries.js';
+import { MIGRATION_VERSION } from '../../../consts.js';
export async function cmd({
dbConfig,
@@ -75,7 +75,7 @@ async function pushSchema({
const requestBody = {
snapshot: currentSnapshot,
sql: statements,
- experimentalVersion: 1,
+ version: MIGRATION_VERSION,
};
if (isDryRun) {
console.info('[DRY RUN] Batch query:', JSON.stringify(requestBody, null, 2));
diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts
index 130b53889..ecef78b44 100644
--- a/packages/db/src/core/cli/migration-queries.ts
+++ b/packages/db/src/core/cli/migration-queries.ts
@@ -32,6 +32,7 @@ import {
columnSchema,
} from '../types.js';
import { getRemoteDatabaseUrl } from '../utils.js';
+import { MIGRATION_VERSION } from '../consts.js';
const sqlite = new SQLiteAsyncDialect();
const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
@@ -437,11 +438,11 @@ export async function getProductionCurrentSnapshot({
export function createCurrentSnapshot({ tables = {} }: DBConfig): DBSnapshot {
const schema = JSON.parse(JSON.stringify(tables));
- return { experimentalVersion: 1, schema };
+ return { version: MIGRATION_VERSION, schema };
}
export function createEmptySnapshot(): DBSnapshot {
- return { experimentalVersion: 1, schema: {} };
+ return { version: MIGRATION_VERSION, schema: {} };
}
export function formatDataLossMessage(confirmations: string[], isColor = true): string {
diff --git a/packages/db/src/core/consts.ts b/packages/db/src/core/consts.ts
index bf295a2dc..cc7f59b9a 100644
--- a/packages/db/src/core/consts.ts
+++ b/packages/db/src/core/consts.ts
@@ -15,3 +15,5 @@ export const VIRTUAL_MODULE_ID = 'astro:db';
export const DB_PATH = '.astro/content.db';
export const CONFIG_FILE_NAMES = ['config.ts', 'config.js', 'config.mts', 'config.mjs'];
+
+export const MIGRATION_VERSION = "2024-03-12";
diff --git a/packages/db/src/core/types.ts b/packages/db/src/core/types.ts
index 36b7eefa5..a88f75df9 100644
--- a/packages/db/src/core/types.ts
+++ b/packages/db/src/core/types.ts
@@ -233,11 +233,7 @@ export type DBTable = z.infer<typeof tableSchema>;
export type DBTables = Record<string, DBTable>;
export type DBSnapshot = {
schema: Record<string, DBTable>;
- /**
- * Snapshot version. Breaking changes to the snapshot format increment this number.
- * @todo Rename to "version" once closer to release.
- */
- experimentalVersion: number;
+ version: string;
};
export const dbConfigSchema = z.object({
diff --git a/packages/db/test/unit/column-queries.test.js b/packages/db/test/unit/column-queries.test.js
index b18697bc3..50218ec34 100644
--- a/packages/db/test/unit/column-queries.test.js
+++ b/packages/db/test/unit/column-queries.test.js
@@ -7,7 +7,7 @@ import {
import { tableSchema } from '../../dist/core/types.js';
import { column, defineTable } from '../../dist/runtime/config.js';
import { NOW } from '../../dist/runtime/index.js';
-import { getCreateTableQuery } from '../../dist/runtime/queries.js';
+import { MIGRATION_VERSION } from '../../dist/core/consts.js';
const TABLE_NAME = 'Users';
@@ -34,8 +34,8 @@ function userChangeQueries(oldTable, newTable) {
function configChangeQueries(oldCollections, newCollections) {
return getMigrationQueries({
- oldSnapshot: { schema: oldCollections, experimentalVersion: 1 },
- newSnapshot: { schema: newCollections, experimentalVersion: 1 },
+ oldSnapshot: { schema: oldCollections, version: MIGRATION_VERSION },
+ newSnapshot: { schema: newCollections, version: MIGRATION_VERSION },
});
}