Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: has trialed db support (#1712)

Will Hutchinsonb069e0ad7c14
diff --git a/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs b/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs
index c6ea29f35e..9682594199 100644
--- a/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs
+++ b/rust/cloud-storage/authentication_service/src/api/user/get_legacy_user_permissions.rs
@@ -132,7 +132,7 @@ pub async fn handler(
_ => None,
},
has_chrome_ext: legacy_user_info.has_chrome_ext,
- has_trialed: true, // setting to true until we deprecate the usage on the frontend
+ has_trialed: legacy_user_info.has_trialed,
ai_data_consent: legacy_user_info.ai_data_consent,
})
}
diff --git a/rust/cloud-storage/authentication_service/src/api/webhooks/user/stripe_webhook.rs b/rust/cloud-storage/authentication_service/src/api/webhooks/user/stripe_webhook.rs
index 1d5f265f7e..2f41ef2697 100644
--- a/rust/cloud-storage/authentication_service/src/api/webhooks/user/stripe_webhook.rs
+++ b/rust/cloud-storage/authentication_service/src/api/webhooks/user/stripe_webhook.rs
@@ -213,6 +213,9 @@ async fn handle_customer_subscription_event(
}
if subscription_status == "trialing" {
+ // set has_trialed in macro_user table
+ macro_db_client::user::patch::update_macro_user_has_trialed(&ctx.db, &email, true).await?;
+
// Add has_trialed: true to stripe customer metadata
let mut params = stripe::UpdateCustomer::new();
let mut metadata = HashMap::new();
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
deleted file mode 100644
index d2b084cf10..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[],\n $4::JSONB[]\n ) AS u(id, entity_id, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
deleted file mode 100644
index 6d97183829..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n NULL\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[]\n ) AS u(id, entity_id, property_definition_id)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3ebdcbdf2d5d47adc0438e324ff6f6ce9c4a9d638a72f159f319a6f51ebcf4b2.json b/rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.json
similarity index 58%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-3ebdcbdf2d5d47adc0438e324ff6f6ce9c4a9d638a72f159f319a6f51ebcf4b2.json
rename to rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.json
index a2bd080005..3e10ff4284 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-3ebdcbdf2d5d47adc0438e324ff6f6ce9c4a9d638a72f159f319a6f51ebcf4b2.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n \"id\" as \"user_id\",\n \"email\" as \"email\",\n \"stripeCustomerId\" as \"stripe_customer_id?\",\n \"name\" as name,\n \"tutorialComplete\" as tutorial_complete,\n \"group\" as \"group?\",\n \"hasChromeExt\" as has_chrome_ext,\n \"aiDataConsent\" as ai_data_consent\n FROM \"User\"\n WHERE \"id\" = $1\n ",
+ "query": "\n SELECT\n u.\"id\" as \"user_id\",\n u.\"email\" as \"email\",\n u.\"stripeCustomerId\" as \"stripe_customer_id?\",\n u.\"name\" as name,\n u.\"tutorialComplete\" as tutorial_complete,\n u.\"group\" as \"group?\",\n u.\"hasChromeExt\" as has_chrome_ext,\n u.\"aiDataConsent\" as ai_data_consent,\n mu.has_trialed as has_trialed\n FROM \"User\" u\n JOIN \"macro_user\" mu ON u.macro_user_id = mu.id\n WHERE u.\"id\" = $1\n ",
"describe": {
"columns": [
{
@@ -42,6 +42,11 @@
"ordinal": 7,
"name": "ai_data_consent",
"type_info": "Bool"
+ },
+ {
+ "ordinal": 8,
+ "name": "has_trialed",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -57,8 +62,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "3ebdcbdf2d5d47adc0438e324ff6f6ce9c4a9d638a72f159f319a6f51ebcf4b2"
+ "hash": "8a7231404c684a133961181ee74af7cb5142a2e5e80077355bc86b068d90ba2d"
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json
new file mode 100644
index 0000000000..4519ec280c
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE macro_user\n SET has_trialed = $2\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
deleted file mode 100644
index 9d717fa5f9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT property_definition_id, values\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = 'TASK'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "values",
- "type_info": "Jsonb"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- true
- ]
- },
- "hash": "9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-87c5d299a2e108d458bc71203c4a434880da2bbd24cb8de204f514323233aad5.json b/rust/cloud-storage/macro_db_client/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json
similarity index 60%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-87c5d299a2e108d458bc71203c4a434880da2bbd24cb8de204f514323233aad5.json
rename to rust/cloud-storage/macro_db_client/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json
index 081a2d29ad..5b3d78de3a 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-87c5d299a2e108d458bc71203c4a434880da2bbd24cb8de204f514323233aad5.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"macro_user\" (\"id\", \"username\", \"stripe_customer_id\", \"email\")\n VALUES ($1, $2, $3, $4)\n RETURNING id\n ",
+ "query": "\n INSERT INTO \"macro_user\" (\"id\", \"username\", \"stripe_customer_id\", \"email\", \"has_trialed\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
"describe": {
"columns": [
{
@@ -14,12 +14,13 @@
"Uuid",
"Text",
"Text",
- "Text"
+ "Text",
+ "Bool"
]
},
"nullable": [
false
]
},
- "hash": "87c5d299a2e108d458bc71203c4a434880da2bbd24cb8de204f514323233aad5"
+ "hash": "e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b"
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
deleted file mode 100644
index 182e0858ba..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n u.entity_type::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::TEXT[],\n $4::UUID[],\n $5::JSONB[]\n ) AS u(id, entity_id, entity_type, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069"
-}
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260227152447_add_has_trialed_to_macro_user.sql b/rust/cloud-storage/macro_db_client/migrations/20260227152447_add_has_trialed_to_macro_user.sql
new file mode 100644
index 0000000000..3dcf8c267e
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260227152447_add_has_trialed_to_macro_user.sql
@@ -0,0 +1,3 @@
+-- By default set all existing users to has_trialed true
+-- We can manually alter this value later with a script calling stripe to sync
+ALTER TABLE macro_user ADD COLUMN has_trialed bool DEFAULT TRUE NOT NULL;
diff --git a/rust/cloud-storage/macro_db_client/src/user/create_user.rs b/rust/cloud-storage/macro_db_client/src/user/create_user.rs
index cfc868d102..c32b5d6a8f 100644
--- a/rust/cloud-storage/macro_db_client/src/user/create_user.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/create_user.rs
@@ -22,14 +22,15 @@ pub async fn create_user(
// Create macro user
let macro_user_id = sqlx::query!(
r#"
- INSERT INTO "macro_user" ("id", "username", "stripe_customer_id", "email")
- VALUES ($1, $2, $3, $4)
+ INSERT INTO "macro_user" ("id", "username", "stripe_customer_id", "email", "has_trialed")
+ VALUES ($1, $2, $3, $4, $5)
RETURNING id
"#,
&id,
username,
stripe_customer_id,
- email
+ email,
+ false // has_trialed
)
.map(|row| row.id)
.fetch_one(&mut *transaction)
diff --git a/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs b/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs
index bb03340afa..152b842314 100644
--- a/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/get/get_legacy_user_info.rs
@@ -10,6 +10,7 @@ pub struct LegacyUserInfo {
pub group: Option<String>,
pub has_chrome_ext: bool,
pub ai_data_consent: bool,
+ pub has_trialed: bool,
}
/// Gets the legacy user info
@@ -22,16 +23,18 @@ pub async fn get_legacy_user_info(
LegacyUserInfo,
r#"
SELECT
- "id" as "user_id",
- "email" as "email",
- "stripeCustomerId" as "stripe_customer_id?",
- "name" as name,
- "tutorialComplete" as tutorial_complete,
- "group" as "group?",
- "hasChromeExt" as has_chrome_ext,
- "aiDataConsent" as ai_data_consent
- FROM "User"
- WHERE "id" = $1
+ u."id" as "user_id",
+ u."email" as "email",
+ u."stripeCustomerId" as "stripe_customer_id?",
+ u."name" as name,
+ u."tutorialComplete" as tutorial_complete,
+ u."group" as "group?",
+ u."hasChromeExt" as has_chrome_ext,
+ u."aiDataConsent" as ai_data_consent,
+ mu.has_trialed as has_trialed
+ FROM "User" u
+ JOIN "macro_user" mu ON u.macro_user_id = mu.id
+ WHERE u."id" = $1
"#,
user_id.as_ref()
)
diff --git a/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs b/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
index ac5fe0aaaa..fc0a412192 100644
--- a/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
@@ -1,7 +1,29 @@
-use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use macro_user_id::{email::Email, lowercased::Lowercase, user_id::MacroUserId};
pub mod add_user_role;
+/// Given a users email, it will udpate their has_trialed
+#[tracing::instrument(skip_all, err)]
+pub async fn update_macro_user_has_trialed<'a>(
+ db: &sqlx::Pool<sqlx::Postgres>,
+ email: &Email<Lowercase<'a>>,
+ has_trialed: bool,
+) -> anyhow::Result<()> {
+ sqlx::query!(
+ r#"
+ UPDATE macro_user
+ SET has_trialed = $2
+ WHERE email = $1
+ "#,
+ email.as_ref(),
+ has_trialed,
+ )
+ .execute(db)
+ .await?;
+
+ Ok(())
+}
+
pub async fn update_macro_user_id(
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
user_id: &str,