Skip to content

Commit

Permalink
Support deprecating Web Vitals table (#11096)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored May 20, 2024
1 parent 8e465d6 commit 0dbd8ee
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/good-turtles-guess.md
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions packages/integrations/web-vitals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions packages/integrations/web-vitals/src/db-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/web-vitals/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 0dbd8ee

Please sign in to comment.