Skip to content

Commit

Permalink
chore(supabase): wip - scripts that autogenerate main db types
Browse files Browse the repository at this point in the history
  • Loading branch information
jkergal committed Dec 12, 2023
1 parent cc9e704 commit 293aba6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
23 changes: 23 additions & 0 deletions database/scripts/generate-main-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Chemin vers le fichier de types générés par Supabase
inputFile="/home/jkergal/dev/drafty/database/types/database.types.ts"

# Chemin vers le fichier de sortie main.types.ts
outputFile="/home/jkergal/dev/drafty/database/types/main.types.ts"

# Extrait les noms des tables du fichier de types
tableNames=($(grep -oE '\b[a-z][a-zA-Z0-9_]*: \{' "$inputFile" | sed 's/: {//'))

# Génère dynamiquement le contenu du fichier main.types.ts
> "$outputFile"
echo "import { SupabackTypes } from './generic.types'" >> "$outputFile"
echo "" >> "$outputFile"
echo $tableNames

# Génère les types pour chaque table et les déclarations
for tableName in "${tableNames[@]}"; do
echo "export type $tableName = SupabackTypes<'$tableName'>" >> "$outputFile"
done

echo "Le fichier $outputFile a été généré avec succès."
6 changes: 6 additions & 0 deletions database/types/_main.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { SupabackTypes } from './generic.types';

export type DraftyConfig = SupabackTypes<'drafty_configurations'>;
export type EnrollmentMessage = SupabackTypes<'enrollment_messages'>;
export type GameTable = SupabackTypes<'game_tables'>;
export type Pod = SupabackTypes<'pods'>;
21 changes: 16 additions & 5 deletions database/types/main.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { SupabackTypes } from './generic.types';
import { SupabackTypes } from './generic.types'

export type DraftyConfig = SupabackTypes<'drafty_configurations'>;
export type EnrollmentMessage = SupabackTypes<'enrollment_messages'>;
export type GameTable = SupabackTypes<'game_tables'>;
export type Pod = SupabackTypes<'pods'>;
export type public = SupabackTypes<'public'>
export type drafty_configurations = SupabackTypes<'drafty_configurations'>
export type enrollment_messages = SupabackTypes<'enrollment_messages'>
export type game_tables = SupabackTypes<'game_tables'>
export type pods = SupabackTypes<'pods'>
export type storage = SupabackTypes<'storage'>
export type buckets = SupabackTypes<'buckets'>
export type migrations = SupabackTypes<'migrations'>
export type objects = SupabackTypes<'objects'>
export type can_insert_object = SupabackTypes<'can_insert_object'>
export type extension = SupabackTypes<'extension'>
export type filename = SupabackTypes<'filename'>
export type foldername = SupabackTypes<'foldername'>
export type get_size_by_bucket = SupabackTypes<'get_size_by_bucket'>
export type search = SupabackTypes<'search'>

0 comments on commit 293aba6

Please sign in to comment.