Skip to content

Commit

Permalink
db: rename experimentalVersion to version (#10348)
Browse files Browse the repository at this point in the history
* db: rename experimentalVersion to version

* Fix tests

* Update .changeset/fluffy-bobcats-arrive.md

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
  • Loading branch information
matthewp and ematipico authored Mar 7, 2024
1 parent e7eb832 commit 9f422e9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-bobcats-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Rename `experimentalVersion` to `version`
4 changes: 2 additions & 2 deletions packages/db/src/core/cli/commands/push/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +10,7 @@ import {
getMigrationQueries,
getProductionCurrentSnapshot,
} from '../../migration-queries.js';
import { MIGRATION_VERSION } from '../../../consts.js';

export async function cmd({
dbConfig,
Expand Down Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/db/src/core/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
6 changes: 1 addition & 5 deletions packages/db/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions packages/db/test/unit/column-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 },
});
}

Expand Down

0 comments on commit 9f422e9

Please sign in to comment.