Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deprecating Web Vitals table #11096

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we set this only when running a db push? Or is it intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you might want it in dev etc. too? If you happened to run it while deprecated. Probably doesn’t matter either way though — I just wanted it to match how a user-defined table might behave really.

return defineDbIntegration({
name: '@astrojs/web-vitals',
hooks: {
Expand Down
Loading