Skip to content

Commit

Permalink
Initial org table and add s2s org management apis (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
byn9826 authored Jan 3, 2025
1 parent a2c97a5 commit b4831a4
Show file tree
Hide file tree
Showing 24 changed files with 1,582 additions and 17 deletions.
112 changes: 112 additions & 0 deletions server/migrations/pg/20250103143000_create_org_table.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
exports.up = function (knex) {
return knex.schema.createTable(
'org',
function (table) {
table.increments('id').primary()
table.string(
'name',
50,
).notNullable()
table.string(
'companyLogoUrl',
250,
).notNullable()
.defaultTo('')
table.string(
'fontFamily',
50,
).notNullable()
.defaultTo('')
table.string(
'fontUrl',
250,
).notNullable()
.defaultTo('')
table.string(
'layoutColor',
20,
).notNullable()
.defaultTo('')
table.string(
'labelColor',
20,
).notNullable()
.defaultTo('')
table.string(
'primaryButtonColor',
20,
).notNullable()
.defaultTo('')
table.string(
'primaryButtonLabelColor',
20,
).notNullable()
.defaultTo('')
table.string(
'primaryButtonBorderColor',
20,
).notNullable()
.defaultTo('')
table.string(
'secondaryButtonColor',
20,
).notNullable()
.defaultTo('')
table.string(
'secondaryButtonLabelColor',
20,
).notNullable()
.defaultTo('')
table.string(
'secondaryButtonBorderColor',
20,
).notNullable()
.defaultTo('')
table.string(
'criticalIndicatorColor',
20,
).notNullable()
.defaultTo('')
table.string(
'emailSenderName',
20,
).notNullable()
.defaultTo('')
table.string(
'termsLink',
250,
).notNullable()
.defaultTo('')
table.string(
'privacyPolicyLink',
250,
).notNullable()
.defaultTo('')
table.string(
'createdAt',
19,
).notNullable()
.defaultTo(knex.raw("to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS')"))
table.string(
'updatedAt',
19,
).notNullable()
.defaultTo(knex.raw("to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS')"))
table.string(
'deletedAt',
19,
).defaultTo(null)
},
)
.then(function () {
return knex.schema.raw(`
CREATE UNIQUE INDEX idx_unique_org_name
ON "org" ("name")
WHERE "deletedAt" IS NULL;
`)
})
}

exports.down = function (knex) {
return knex.schema.dropTable('org')
}
17 changes: 17 additions & 0 deletions server/migrations/pg/20250103143500_add_org_related_scopes.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
exports.up = function (knex) {
return knex('scope').insert([
{
name: 'read_org',
type: 's2s',
note: 'Allows a S2S app to access org-specific data without modifying it.',
},
{
name: 'write_org',
type: 's2s',
note: 'Allows a S2S app to create, update, and delete org-specific data.',
},
])
}

exports.down = function () {
}
23 changes: 23 additions & 0 deletions server/migrations/sqlite/0023_create_org_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE [org] (
"id" integer PRIMARY KEY,
"name" text NOT NULL,
"companyLogoUrl" text NOT NULL DEFAULT "",
"fontFamily" text NOT NULL DEFAULT "",
"fontUrl" text NOT NULL DEFAULT "",
"layoutColor" text NOT NULL DEFAULT "",
"labelColor" text NOT NULL DEFAULT "",
"primaryButtonColor" text NOT NULL DEFAULT "",
"primaryButtonLabelColor" text NOT NULL DEFAULT "",
"primaryButtonBorderColor" text NOT NULL DEFAULT "",
"secondaryButtonColor" text NOT NULL DEFAULT "",
"secondaryButtonLabelColor" text NOT NULL DEFAULT "",
"secondaryButtonBorderColor" text NOT NULL DEFAULT "",
"criticalIndicatorColor" text NOT NULL DEFAULT "",
"emailSenderName" text NOT NULL DEFAULT "",
"termsLink" text NOT NULL DEFAULT "",
"privacyPolicyLink" text NOT NULL DEFAULT "",
"createdAt" text DEFAULT CURRENT_TIMESTAMP,
"updatedAt" text DEFAULT CURRENT_TIMESTAMP,
"deletedAt" text DEFAULT null
);
CREATE UNIQUE INDEX idx_unique_org_name ON org (name) WHERE deletedAt IS NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO scope ("name", "type", "note") values ('read_org', 's2s', 'Allows a S2S app to access org-specific data without modifying it.');
INSERT INTO scope ("name", "type", "note") values ('write_org', 's2s', 'Allows a S2S app to create, update, and delete org-specific data.');
Loading

0 comments on commit b4831a4

Please sign in to comment.