From 0dbd8eeb77065f3ed03f481c8042f2896a5448c4 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Mon, 20 May 2024 16:51:02 +0200 Subject: [PATCH] Support deprecating Web Vitals table (#11096) --- .changeset/good-turtles-guess.md | 5 ++ packages/integrations/web-vitals/README.md | 49 +++++++++++++++++++ .../integrations/web-vitals/src/db-config.ts | 1 + packages/integrations/web-vitals/src/index.ts | 3 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .changeset/good-turtles-guess.md diff --git a/.changeset/good-turtles-guess.md b/.changeset/good-turtles-guess.md new file mode 100644 index 000000000000..28edbffc0483 --- /dev/null +++ b/.changeset/good-turtles-guess.md @@ -0,0 +1,5 @@ +--- +"@astrojs/web-vitals": patch +--- + +Adds support for deprecating the web vitals DB table, so the integration can be removed if desired diff --git a/packages/integrations/web-vitals/README.md b/packages/integrations/web-vitals/README.md index 3a4c5fb0141d..11cc51e1c40c 100644 --- a/packages/integrations/web-vitals/README.md +++ b/packages/integrations/web-vitals/README.md @@ -27,6 +27,55 @@ This **[Astro integration][astro-integration]** enables tracking real-world webs Learn more about [Astro DB](https://docs.astro.build/en/guides/astro-db/) and [deploying with Astro Studio](https://docs.astro.build/en/guides/astro-db/#astro-studio) in the Astro docs. +## Uninstalling + +To remove the Web Vitals integration, follow the Astro DB deprecation process: + +1. Mark the integration as deprecated in `astro.config.mjs`, by setting the `deprecated` option to `true`: + + ```js + import db from '@astrojs/db'; + import webVitals from '@astrojs/web-vitals'; + import { defineConfig } from 'astro/config'; + + export default defineConfig({ + integrations: [ + db(), + // Mark the web vitals integration as deprecated: + webVitals({ deprecated: true }), + ], + // ... + }); + ``` + +2. Push the deprecation to Astro Studio: + + ```sh + npx astro db push + ``` + +3. Remove the web vitals integration in `astro.config.mjs`: + + ```diff + import db from '@astrojs/db'; + - import webVitals from '@astrojs/web-vitals'; + import { defineConfig } from 'astro/config'; + + export default defineConfig({ + integrations: [ + db(), + - webVitals({ deprecated: true }), + ], + // ... + }); + ``` + +4. Push the table deletion to Astro Studio: + + ```sh + npx astro db push + ``` + ## Support - Get help in the [Astro Discord][discord]. Post questions in our `#support` forum, or visit our dedicated `#dev` channel to discuss current development and more! diff --git a/packages/integrations/web-vitals/src/db-config.ts b/packages/integrations/web-vitals/src/db-config.ts index b7969b14bff2..eaaf65ba62ba 100644 --- a/packages/integrations/web-vitals/src/db-config.ts +++ b/packages/integrations/web-vitals/src/db-config.ts @@ -11,6 +11,7 @@ const Metric = defineTable({ rating: column.text(), timestamp: column.date(), }, + deprecated: Boolean(process.env.DEPRECATE_WEB_VITALS) ?? false, }); // export const AstrojsWebVitals_Metric = asDrizzleTable('AstrojsWebVitals_Metric', Metric); diff --git a/packages/integrations/web-vitals/src/index.ts b/packages/integrations/web-vitals/src/index.ts index f8a5ad433496..a9335826687b 100644 --- a/packages/integrations/web-vitals/src/index.ts +++ b/packages/integrations/web-vitals/src/index.ts @@ -2,7 +2,8 @@ import { defineDbIntegration } from '@astrojs/db/utils'; import { AstroError } from 'astro/errors'; import { WEB_VITALS_ENDPOINT_PATH } from './constants.js'; -export default function webVitals() { +export default function webVitals({ deprecated }: { deprecated?: boolean } = {}) { + process.env.DEPRECATE_WEB_VITALS = deprecated ? 'true' : undefined; return defineDbIntegration({ name: '@astrojs/web-vitals', hooks: {