Skip to content
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
11 changes: 11 additions & 0 deletions packages/shared/src/db/migrations/0002_confused_lionheart.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
SQLite does not support "Set default to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3

Due to that we don't generate migration automatically and it has to be done manually
*/--> statement-breakpoint
ALTER TABLE orgs ADD `stripe_subscription_id` text(191);--> statement-breakpoint
ALTER TABLE orgs ADD `stripe_current_period_end` integer;--> statement-breakpoint
CREATE UNIQUE INDEX `orgs_stripe_subscription_id_key` ON `orgs` (`stripe_subscription_id`);
317 changes: 317 additions & 0 deletions packages/shared/src/db/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
{
"version": "5",
"dialect": "sqlite",
"id": "781d35e2-75fe-4cf4-83fe-67431c7c067f",
"prevId": "b5522eea-ae7b-4918-abb2-adb620f94b5c",
"tables": {
"org_invites": {
"name": "org_invites",
"columns": {
"id": {
"name": "id",
"type": "text(191)",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"token": {
"name": "token",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires": {
"name": "expires",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"sender_user_id": {
"name": "sender_user_id",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"org_id": {
"name": "org_id",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"role": {
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'read'"
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
}
},
"indexes": {
"token_org_invites_id_key": {
"name": "token_org_invites_id_key",
"columns": [
"token"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"org_users": {
"name": "org_users",
"columns": {
"id": {
"name": "id",
"type": "text(191)",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"role": {
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'read'"
},
"org_id": {
"name": "org_id",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"orgs": {
"name": "orgs",
"columns": {
"id": {
"name": "id",
"type": "text(191)",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text(191)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"plan": {
"name": "plan",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'free'"
},
"stripe_customer_id": {
"name": "stripe_customer_id",
"type": "text(191)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"stripe_subscription_id": {
"name": "stripe_subscription_id",
"type": "text(191)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"stripe_current_period_end": {
"name": "stripe_current_period_end",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
}
},
"indexes": {
"orgs_stripe_customer_id_key": {
"name": "orgs_stripe_customer_id_key",
"columns": [
"stripe_customer_id"
],
"isUnique": true
},
"orgs_stripe_subscription_id_key": {
"name": "orgs_stripe_subscription_id_key",
"columns": [
"stripe_subscription_id"
],
"isUnique": true
},
"orgs_name_id_key": {
"name": "orgs_name_id_key",
"columns": [
"name"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "text(191)",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"stripe_customer_id": {
"name": "stripe_customer_id",
"type": "text(191)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"stripe_subscription_id": {
"name": "stripe_subscription_id",
"type": "text(191)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"stripe_price_id": {
"name": "stripe_price_id",
"type": "text(191)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"stripe_current_period_end": {
"name": "stripe_current_period_end",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
}
},
"indexes": {
"users_stripe_customer_id_key": {
"name": "users_stripe_customer_id_key",
"columns": [
"stripe_customer_id"
],
"isUnique": true
},
"users_stripe_subscription_id_key": {
"name": "users_stripe_subscription_id_key",
"columns": [
"stripe_subscription_id"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
9 changes: 8 additions & 1 deletion packages/shared/src/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1710095002592,
"tag": "0001_glorious_masked_marvel",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 1769615790664,
"tag": "0002_confused_lionheart",
"breakpoints": true
}
]
}
}
9 changes: 8 additions & 1 deletion packages/shared/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ export const orgs = sqliteTable(
{
id: text("id", { length: 191 }).primaryKey().notNull(),
name: text("name", { length: 191 }).notNull(),
plan: text("plan", { enum: [Plan.FREE, Plan.PAID] })
plan: text("plan", { enum: [Plan.FREE, Plan.PRO] })
.default(Plan.FREE)
.notNull(),
stripeCustomerId: text("stripe_customer_id", { length: 191 }),
stripeSubscriptionId: text("stripe_subscription_id", { length: 191 }),
stripeCurrentPeriodEnd: integer("stripe_current_period_end", {
mode: "timestamp",
}),
createdAt: integer("created_at", {
mode: "timestamp",
})
Expand All @@ -71,6 +75,9 @@ export const orgs = sqliteTable(
stripeCustomerIdKey: uniqueIndex("orgs_stripe_customer_id_key").on(
table.stripeCustomerId
),
stripeSubscriptionIdKey: uniqueIndex(
"orgs_stripe_subscription_id_key"
).on(table.stripeSubscriptionId),
nameIdKey: uniqueIndex("orgs_name_id_key").on(table.name),
};
}
Expand Down
Loading