Home / File/ reset-queries.test.js — astro Source File

reset-queries.test.js — astro Source File

Architecture documentation for reset-queries.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  a759e4f4_5be7_4d18_579b_23b6904da0c5["reset-queries.test.js"]
  5c566864_9aa2_d0a5_e553_73066212573e["../../dist/core/cli/migration-queries.js"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> 5c566864_9aa2_d0a5_e553_73066212573e
  ab9b8d2c_2800_236b_70dd_6d2cb58ddf49["../../dist/core/consts.js"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> ab9b8d2c_2800_236b_70dd_6d2cb58ddf49
  82f386b6_476d_fbec_cdfc_c43346cc3546["../../dist/core/schemas.js"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> 82f386b6_476d_fbec_cdfc_c43346cc3546
  270980c1_198c_fa0d_1be9_7fa4ce6885d0["../../dist/runtime/virtual.js"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> 270980c1_198c_fa0d_1be9_7fa4ce6885d0
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  a759e4f4_5be7_4d18_579b_23b6904da0c5 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style a759e4f4_5be7_4d18_579b_23b6904da0c5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getMigrationQueries } from '../../dist/core/cli/migration-queries.js';
import { MIGRATION_VERSION } from '../../dist/core/consts.js';
import { tableSchema } from '../../dist/core/schemas.js';
import { column, defineTable } from '../../dist/runtime/virtual.js';

const TABLE_NAME = 'Users';

// `parse` to resolve schema transformations
// ex. convert column.date() to ISO strings
const userInitial = tableSchema.parse(
	defineTable({
		columns: {
			name: column.text(),
			age: column.number(),
			email: column.text({ unique: true }),
			mi: column.text({ optional: true }),
		},
	}),
);

describe('force reset', () => {
	describe('getMigrationQueries', () => {
		it('should drop table and create new version', async () => {
			const oldTables = { [TABLE_NAME]: userInitial };
			const newTables = { [TABLE_NAME]: userInitial };
			const { queries } = await getMigrationQueries({
				oldSnapshot: { schema: oldTables, version: MIGRATION_VERSION },
				newSnapshot: { schema: newTables, version: MIGRATION_VERSION },
				reset: true,
			});

			assert.deepEqual(queries, [
				`DROP TABLE IF EXISTS "${TABLE_NAME}"`,
				`CREATE TABLE "${TABLE_NAME}" (_id INTEGER PRIMARY KEY, "name" text NOT NULL, "age" integer NOT NULL, "email" text NOT NULL UNIQUE, "mi" text)`,
			]);
		});

		it('should not drop table when previous snapshot did not have it', async () => {
			const oldTables = {};
			const newTables = { [TABLE_NAME]: userInitial };
			const { queries } = await getMigrationQueries({
				oldSnapshot: { schema: oldTables, version: MIGRATION_VERSION },
				newSnapshot: { schema: newTables, version: MIGRATION_VERSION },
				reset: true,
			});

			assert.deepEqual(queries, [
				`CREATE TABLE "${TABLE_NAME}" (_id INTEGER PRIMARY KEY, "name" text NOT NULL, "age" integer NOT NULL, "email" text NOT NULL UNIQUE, "mi" text)`,
			]);
		});
	});
});

Domain

Dependencies

  • ../../dist/core/cli/migration-queries.js
  • ../../dist/core/consts.js
  • ../../dist/core/schemas.js
  • ../../dist/runtime/virtual.js
  • node:test
  • strict

Frequently Asked Questions

What does reset-queries.test.js do?
reset-queries.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does reset-queries.test.js depend on?
reset-queries.test.js imports 6 module(s): ../../dist/core/cli/migration-queries.js, ../../dist/core/consts.js, ../../dist/core/schemas.js, ../../dist/runtime/virtual.js, node:test, strict.
Where is reset-queries.test.js in the architecture?
reset-queries.test.js is located at packages/db/test/unit/reset-queries.test.js (domain: CoreAstro, directory: packages/db/test/unit).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free