Add pretty formatting (#29)

* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
This commit is contained in:
Martin Braquet
2026-02-20 17:32:27 +01:00
committed by GitHub
parent 1994697fa1
commit ba9b3cfb06
695 changed files with 22382 additions and 23209 deletions

View File

@@ -1,11 +1,11 @@
import { removeUndefinedProps } from 'common/util/object'
import { runScript } from './run-script'
import { log } from 'shared/monitoring/log'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import { bulkUpdateData } from 'shared/supabase/utils'
import { chunk } from 'lodash'
import {removeUndefinedProps} from 'common/util/object'
import {runScript} from './run-script'
import {log} from 'shared/monitoring/log'
import {createSupabaseDirectClient} from 'shared/supabase/init'
import {bulkUpdateData} from 'shared/supabase/utils'
import {chunk} from 'lodash'
runScript(async ({ pg }) => {
runScript(async ({pg}) => {
const directClient = createSupabaseDirectClient()
// Get all users and their corresponding profiles
@@ -17,9 +17,9 @@ runScript(async ({ pg }) => {
log('Found', users.length, 'users to migrate')
const updates = [] as { id: string; link: {} }[]
const updates = [] as {id: string; link: {}}[]
for (const { id, data, twitter } of users) {
for (const {id, data, twitter} of users) {
const add = removeUndefinedProps({
discord: data.discordHandle,
manifold: data.manifoldHandle,
@@ -32,7 +32,7 @@ runScript(async ({ pg }) => {
})
if (Object.keys(add).length) {
updates.push({ id, link: { ...add, ...(data.link || {}) } })
updates.push({id, link: {...add, ...(data.link || {})}})
}
}
@@ -54,6 +54,6 @@ runScript(async ({ pg }) => {
COALESCE((data -> 'link'), '{}'::jsonb),
true
)
where data -> 'link' is null`
where data -> 'link' is null`,
)
})

View File

@@ -1,13 +1,8 @@
import { runScript } from './run-script'
import {
renderSql,
select,
from,
where,
} from 'shared/supabase/sql-builder'
import { SupabaseDirectClient } from 'shared/supabase/init'
import {runScript} from './run-script'
import {from, renderSql, select, where} from 'shared/supabase/sql-builder'
import {SupabaseDirectClient} from 'shared/supabase/init'
runScript(async ({ pg }) => {
runScript(async ({pg}) => {
const tests = [
'mention',
'contract-mention',
@@ -28,7 +23,7 @@ const getNodes = async (pg: SupabaseDirectClient, nodeName: string) => {
const commentQuery = renderSql(
select('id, user_id, on_user_id, content'),
from('profile_comments'),
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeName}")')`)
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeName}")')`),
)
const comments = await pg.manyOrNone(commentQuery)
@@ -44,7 +39,7 @@ const getNodes = async (pg: SupabaseDirectClient, nodeName: string) => {
const messageQuery = renderSql(
select('id, user_id, channel_id, content'),
from('private_user_messages'),
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeName}")')`)
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeName}")')`),
)
const messages = await pg.manyOrNone(messageQuery)
@@ -60,7 +55,7 @@ const getNodes = async (pg: SupabaseDirectClient, nodeName: string) => {
const users = renderSql(
select('user_id, bio'),
from('profiles'),
where(`jsonb_path_exists(bio::jsonb, '$.**.type ? (@ == "${nodeName}")')`)
where(`jsonb_path_exists(bio::jsonb, '$.**.type ? (@ == "${nodeName}")')`),
)
const usersWithMentions = await pg.manyOrNone(users)

View File

@@ -1,17 +1,15 @@
import * as fs from 'fs/promises'
import { execSync } from 'child_process'
import { type SupabaseDirectClient } from 'shared/supabase/init'
import { runScript } from 'run-script'
import {execSync} from 'child_process'
import {type SupabaseDirectClient} from 'shared/supabase/init'
import {runScript} from 'run-script'
const outputDir = `../supabase/`
runScript(async ({ pg }) => {
runScript(async ({pg}) => {
// make the output directory if it doesn't exist
execSync(`mkdir -p ${outputDir}`)
// delete all sql files except seed.sql
execSync(
`cd ${outputDir} && find *.sql -type f ! -name seed.sql -delete || true`
)
execSync(`cd ${outputDir} && find *.sql -type f ! -name seed.sql -delete || true`)
await generateSQLFiles(pg)
})
@@ -50,7 +48,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
AND d.adnum = a.attnum
WHERE table_schema = 'public' AND table_name = $1
ORDER BY column_name`,
[tableName]
[tableName],
)
const checks = await pg.manyOrNone<{
@@ -68,7 +66,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
AND NOT cc.check_clause ilike '% IS NOT NULL'
AND tc.table_schema = 'public'
AND tc.table_name = $1`,
[tableName]
[tableName],
)
const primaryKeys = await pg.map(
@@ -84,7 +82,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
AND ccu.column_name = c.column_name
WHERE constraint_type = 'PRIMARY KEY' AND tc.table_schema = 'public' AND tc.table_name = $1`,
[tableName],
(row) => row.column_name as string
(row) => row.column_name as string,
)
const foreignKeys = await pg.manyOrNone<{
@@ -101,7 +99,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
WHERE
contype = 'f'
AND conrelid = $1::regclass`,
[tableName]
[tableName],
)
const triggers = await pg.manyOrNone<{
@@ -116,13 +114,13 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
WHERE
tgrelid = $1::regclass
AND NOT tgisinternal`,
[tableName]
[tableName],
)
const rlsEnabled = await pg.one(
`SELECT relrowsecurity
FROM pg_class
WHERE oid = $1::regclass`,
[tableName]
[tableName],
)
const rls = !!rlsEnabled.relrowsecurity
@@ -144,7 +142,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
pg_policy
WHERE
polrelid = $1::regclass`,
[tableName]
[tableName],
)
const indexes = await pg.manyOrNone<{
@@ -161,7 +159,7 @@ async function getTableInfo(pg: SupabaseDirectClient, tableName: string) {
AND tablename = $1
ORDER BY
indexname`,
[tableName]
[tableName],
)
return {
@@ -190,20 +188,20 @@ async function getFunctions(pg: SupabaseDirectClient) {
WHERE
pronamespace = 'public'::regnamespace
and prokind = 'f'
ORDER BY proname asc, pronargs asc, oid desc`
ORDER BY proname asc, pronargs asc, oid desc`,
)
return rows.filter((f) => !f.definition.includes(`'$libdir/`))
}
async function getViews(pg: SupabaseDirectClient) {
console.debug('Getting views')
return pg.manyOrNone<{ view_name: string; definition: string }>(
return pg.manyOrNone<{view_name: string; definition: string}>(
`SELECT
table_name AS view_name,
view_definition AS definition
FROM information_schema.views
where table_schema = 'public'
ORDER BY table_name asc`
ORDER BY table_name asc`,
)
}
@@ -211,13 +209,11 @@ async function generateSQLFiles(pg: SupabaseDirectClient) {
const tables = await pg.map(
"SELECT tablename FROM pg_tables WHERE schemaname = 'public'",
[],
(row) => row.tablename as string
(row) => row.tablename as string,
)
console.debug(`Getting info for ${tables.length} tables`)
const tableInfos = await Promise.all(
tables.map((table) => getTableInfo(pg, table))
)
const tableInfos = await Promise.all(tables.map((table) => getTableInfo(pg, table)))
const functions = await getFunctions(pg)
const views = await getViews(pg)
@@ -228,13 +224,11 @@ async function generateSQLFiles(pg: SupabaseDirectClient) {
// organize check constraints by column
const checksByColumn: {
[col: string]: { name: string; definition: string }
[col: string]: {name: string; definition: string}
} = {}
const remainingChecks = []
for (const check of tableInfo.checks) {
const matches = tableInfo.columns.filter((c) =>
check.definition.includes(c.name)
)
const matches = tableInfo.columns.filter((c) => check.definition.includes(c.name))
if (matches.length === 1) {
checksByColumn[matches[0].name] = check
@@ -260,8 +254,7 @@ async function generateSQLFiles(pg: SupabaseDirectClient) {
}
if (c.not_null) content += ' NOT NULL'
const check = checksByColumn[c.name]
if (check)
content += ` CONSTRAINT ${check.name} CHECK ${check.definition}`
if (check) content += ` CONSTRAINT ${check.name} CHECK ${check.definition}`
content += ',\n'
}
@@ -351,7 +344,5 @@ async function generateSQLFiles(pg: SupabaseDirectClient) {
await fs.writeFile(`${outputDir}/views.sql`, viewsContent)
console.debug('Prettifying SQL files...')
execSync(
`prettier --write ${outputDir}/*.sql --ignore-path ../supabase/.gitignore`
)
execSync(`prettier --write ${outputDir}/*.sql --ignore-path ../supabase/.gitignore`)
}

View File

@@ -1,16 +1,8 @@
import { runScript } from './run-script'
import {
renderSql,
select,
from,
where,
} from 'shared/supabase/sql-builder'
import { type JSONContent } from '@tiptap/core'
import {runScript} from './run-script'
import {from, renderSql, select, where} from 'shared/supabase/sql-builder'
import {type JSONContent} from '@tiptap/core'
const removeNodesOfType = (
content: JSONContent,
typeToRemove: string
): JSONContent | null => {
const removeNodesOfType = (content: JSONContent, typeToRemove: string): JSONContent | null => {
if (content.type === typeToRemove) {
return null
}
@@ -20,21 +12,21 @@ const removeNodesOfType = (
.map((node) => removeNodesOfType(node, typeToRemove))
.filter((node) => node != null)
return { ...content, content: newContent }
return {...content, content: newContent}
}
// No content to process, return node as is
return content
}
runScript(async ({ pg }) => {
runScript(async ({pg}) => {
const nodeType = 'linkPreview'
console.debug('\nSearching comments for linkPreviews...')
const commentQuery = renderSql(
select('id, content'),
from('profile_comments'),
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeType}")')`)
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeType}")')`),
)
const comments = await pg.manyOrNone(commentQuery)
@@ -56,7 +48,7 @@ runScript(async ({ pg }) => {
const messageQuery = renderSql(
select('id, content'),
from('private_user_messages'),
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeType}")')`)
where(`jsonb_path_exists(content, '$.**.type ? (@ == "${nodeType}")')`),
)
const messages = await pg.manyOrNone(messageQuery)
@@ -67,10 +59,10 @@ runScript(async ({ pg }) => {
console.debug('before', JSON.stringify(msg.content, null, 2))
console.debug('after', JSON.stringify(newContent, null, 2))
await pg.none(
'update private_user_messages set content = $1 where id = $2',
[newContent, msg.id]
)
await pg.none('update private_user_messages set content = $1 where id = $2', [
newContent,
msg.id,
])
console.debug('Updated message:', msg.id)
}
})

View File

@@ -1,9 +1,9 @@
import {initAdmin} from 'shared/init-admin'
import {createSupabaseDirectClient, type SupabaseDirectClient,} from 'shared/supabase/init'
import {refreshConfig} from "common/envs/prod";
import {createSupabaseDirectClient, type SupabaseDirectClient} from 'shared/supabase/init'
import {refreshConfig} from 'common/envs/prod'
export const runScript = async (
main: (services: { pg: SupabaseDirectClient }) => Promise<any> | any
main: (services: {pg: SupabaseDirectClient}) => Promise<any> | any,
) => {
initAdmin()
await initEnvVariables()
@@ -16,9 +16,8 @@ export const runScript = async (
await main({pg})
}
export async function initEnvVariables() {
const {config} = await import('dotenv')
config({ path: __dirname + '/../../.env' })
config({path: __dirname + '/../../.env'})
refreshConfig()
}

View File

@@ -20,10 +20,10 @@
"require": ["tsconfig-paths/register"]
},
"references": [
{ "path": "../../common" },
{ "path": "../shared" },
{ "path": "../api" },
{ "path": "../email" }
{"path": "../../common"},
{"path": "../shared"},
{"path": "../api"},
{"path": "../email"}
],
"compileOnSave": true
}