0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

db: rename experimentalVersion to version (#10348)

* 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>
This commit is contained in:
Matthew Phillips 2024-03-07 11:37:36 -05:00 committed by GitHub
parent e7eb83252e
commit 9f422e9bd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 12 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---
Rename `experimentalVersion` to `version`

View file

@ -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));

View file

@ -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 {

View file

@ -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";

View file

@ -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({

View file

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