mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -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:
parent
e7eb83252e
commit
9f422e9bd3
6 changed files with 16 additions and 12 deletions
5
.changeset/fluffy-bobcats-arrive.md
Normal file
5
.changeset/fluffy-bobcats-arrive.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@astrojs/db": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Rename `experimentalVersion` to `version`
|
|
@ -1,5 +1,4 @@
|
||||||
import type { AstroConfig } from 'astro';
|
import type { AstroConfig } from 'astro';
|
||||||
import { red } from 'kleur/colors';
|
|
||||||
import type { Arguments } from 'yargs-parser';
|
import type { Arguments } from 'yargs-parser';
|
||||||
import { getManagedAppTokenOrExit } from '../../../tokens.js';
|
import { getManagedAppTokenOrExit } from '../../../tokens.js';
|
||||||
import { type DBConfig, type DBSnapshot } from '../../../types.js';
|
import { type DBConfig, type DBSnapshot } from '../../../types.js';
|
||||||
|
@ -11,6 +10,7 @@ import {
|
||||||
getMigrationQueries,
|
getMigrationQueries,
|
||||||
getProductionCurrentSnapshot,
|
getProductionCurrentSnapshot,
|
||||||
} from '../../migration-queries.js';
|
} from '../../migration-queries.js';
|
||||||
|
import { MIGRATION_VERSION } from '../../../consts.js';
|
||||||
|
|
||||||
export async function cmd({
|
export async function cmd({
|
||||||
dbConfig,
|
dbConfig,
|
||||||
|
@ -75,7 +75,7 @@ async function pushSchema({
|
||||||
const requestBody = {
|
const requestBody = {
|
||||||
snapshot: currentSnapshot,
|
snapshot: currentSnapshot,
|
||||||
sql: statements,
|
sql: statements,
|
||||||
experimentalVersion: 1,
|
version: MIGRATION_VERSION,
|
||||||
};
|
};
|
||||||
if (isDryRun) {
|
if (isDryRun) {
|
||||||
console.info('[DRY RUN] Batch query:', JSON.stringify(requestBody, null, 2));
|
console.info('[DRY RUN] Batch query:', JSON.stringify(requestBody, null, 2));
|
||||||
|
|
|
@ -32,6 +32,7 @@ import {
|
||||||
columnSchema,
|
columnSchema,
|
||||||
} from '../types.js';
|
} from '../types.js';
|
||||||
import { getRemoteDatabaseUrl } from '../utils.js';
|
import { getRemoteDatabaseUrl } from '../utils.js';
|
||||||
|
import { MIGRATION_VERSION } from '../consts.js';
|
||||||
|
|
||||||
const sqlite = new SQLiteAsyncDialect();
|
const sqlite = new SQLiteAsyncDialect();
|
||||||
const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
|
const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
|
||||||
|
@ -437,11 +438,11 @@ export async function getProductionCurrentSnapshot({
|
||||||
|
|
||||||
export function createCurrentSnapshot({ tables = {} }: DBConfig): DBSnapshot {
|
export function createCurrentSnapshot({ tables = {} }: DBConfig): DBSnapshot {
|
||||||
const schema = JSON.parse(JSON.stringify(tables));
|
const schema = JSON.parse(JSON.stringify(tables));
|
||||||
return { experimentalVersion: 1, schema };
|
return { version: MIGRATION_VERSION, schema };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createEmptySnapshot(): DBSnapshot {
|
export function createEmptySnapshot(): DBSnapshot {
|
||||||
return { experimentalVersion: 1, schema: {} };
|
return { version: MIGRATION_VERSION, schema: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDataLossMessage(confirmations: string[], isColor = true): string {
|
export function formatDataLossMessage(confirmations: string[], isColor = true): string {
|
||||||
|
|
|
@ -15,3 +15,5 @@ export const VIRTUAL_MODULE_ID = 'astro:db';
|
||||||
export const DB_PATH = '.astro/content.db';
|
export const DB_PATH = '.astro/content.db';
|
||||||
|
|
||||||
export const CONFIG_FILE_NAMES = ['config.ts', 'config.js', 'config.mts', 'config.mjs'];
|
export const CONFIG_FILE_NAMES = ['config.ts', 'config.js', 'config.mts', 'config.mjs'];
|
||||||
|
|
||||||
|
export const MIGRATION_VERSION = "2024-03-12";
|
||||||
|
|
|
@ -233,11 +233,7 @@ export type DBTable = z.infer<typeof tableSchema>;
|
||||||
export type DBTables = Record<string, DBTable>;
|
export type DBTables = Record<string, DBTable>;
|
||||||
export type DBSnapshot = {
|
export type DBSnapshot = {
|
||||||
schema: Record<string, DBTable>;
|
schema: Record<string, DBTable>;
|
||||||
/**
|
version: string;
|
||||||
* Snapshot version. Breaking changes to the snapshot format increment this number.
|
|
||||||
* @todo Rename to "version" once closer to release.
|
|
||||||
*/
|
|
||||||
experimentalVersion: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dbConfigSchema = z.object({
|
export const dbConfigSchema = z.object({
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
import { tableSchema } from '../../dist/core/types.js';
|
import { tableSchema } from '../../dist/core/types.js';
|
||||||
import { column, defineTable } from '../../dist/runtime/config.js';
|
import { column, defineTable } from '../../dist/runtime/config.js';
|
||||||
import { NOW } from '../../dist/runtime/index.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';
|
const TABLE_NAME = 'Users';
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ function userChangeQueries(oldTable, newTable) {
|
||||||
|
|
||||||
function configChangeQueries(oldCollections, newCollections) {
|
function configChangeQueries(oldCollections, newCollections) {
|
||||||
return getMigrationQueries({
|
return getMigrationQueries({
|
||||||
oldSnapshot: { schema: oldCollections, experimentalVersion: 1 },
|
oldSnapshot: { schema: oldCollections, version: MIGRATION_VERSION },
|
||||||
newSnapshot: { schema: newCollections, experimentalVersion: 1 },
|
newSnapshot: { schema: newCollections, version: MIGRATION_VERSION },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue