Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -22,6 +22,49 @@ Kurulumda genel yaklaşım şu:
|
||||
|
||||
Repo içinde `supabase/` ve `docs/database/` klasörleri tutulmaya devam eder. Bunları deployment sırasında otomatik çalıştıran bir script yoktur. Bu dosyalar benim SQL kayıtlarım, migration notlarım ve schema geçmişim olarak durur.
|
||||
|
||||
## Tek Seferlik Kurulum SQL'i
|
||||
|
||||
Yeni bir Supabase projesini Neta için hazırlamanın en kolay yolu `supabase/setup.sql` dosyasını çalıştırmak. Bu dosya `supabase/schema.sql` ve `supabase/migrations/0002..0011` arasındaki migration dosyalarının tek dosyada birleştirilmiş hâlidir.
|
||||
|
||||
Demo seed verisi bu dosyaya dahil değildir. Production kurulumda örnek veri istemediğim için seed ayrı tutulur.
|
||||
|
||||
### Supabase SQL Editor ile
|
||||
|
||||
Supabase panelinde şu bölümü açın:
|
||||
|
||||
```txt
|
||||
SQL Editor -> New query
|
||||
```
|
||||
|
||||
Sonra `supabase/setup.sql` dosyasının tamamını kopyalayıp tek seferde çalıştırın.
|
||||
|
||||
Bu işlem şunları kurar:
|
||||
|
||||
- Tablolar.
|
||||
- Foreign key ve check constraint'leri.
|
||||
- Index'ler.
|
||||
- Trigger ve function'lar.
|
||||
- RLS policy'leri.
|
||||
- Storage bucket kayıtları ve storage policy'leri.
|
||||
|
||||
### Terminalden Tek Komut ile
|
||||
|
||||
Supabase connection string'iniz varsa aynı kurulumu tek `psql` komutuyla da çalıştırabilirsiniz:
|
||||
|
||||
```bash
|
||||
psql "postgresql://postgres:[PASSWORD]@[HOST]:5432/postgres" -v ON_ERROR_STOP=1 -f supabase/setup.sql
|
||||
```
|
||||
|
||||
Supabase hosted projelerde connection string'i şuradan alabilirsiniz:
|
||||
|
||||
```txt
|
||||
Project Settings -> Database -> Connection string
|
||||
```
|
||||
|
||||
Şifre, host ve port bilgilerini kendi projenize göre değiştirmelisiniz.
|
||||
|
||||
Bu komut başarılı bittikten sonra Supabase tarafı Neta uygulamasına hazır hâle gelir.
|
||||
|
||||
## Gerekli Tablolar
|
||||
|
||||
Neta şu public tabloları bekler:
|
||||
@@ -104,7 +147,21 @@ Bu yüzden `SUPABASE_SERVICE_ROLE_KEY` zorunludur. Bu key asla browser'a gönder
|
||||
|
||||
## SQL Dosyaları Nasıl Kullanılmalı?
|
||||
|
||||
Bu repodaki SQL dosyalarını otomatik migration sistemi gibi düşünmüyorum. Bunlar benim migration geçmişimi ve Supabase tarafında beklenen yapıyı belgeleyen kaynaklar.
|
||||
Yeni kurulum için en pratik dosya:
|
||||
|
||||
```txt
|
||||
supabase/setup.sql
|
||||
```
|
||||
|
||||
Bu dosya tek seferde çalıştırılacak kurulum dosyasıdır.
|
||||
|
||||
Parçalı dosyalar ise migration geçmişini ve geliştirme sürecini belgelemek için korunur:
|
||||
|
||||
```txt
|
||||
supabase/schema.sql
|
||||
supabase/migrations/
|
||||
docs/database/
|
||||
```
|
||||
|
||||
Yeni bir kurulum yaparken en güvenilir kaynak, çalışan Supabase projesinden aldığınız güncel SQL çıktısıdır. Supabase panelindeki "copy as SQL" çıktısı bu yüzden önemlidir.
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ Deploy'dan önce hazır olması gerekenler:
|
||||
- Supabase tabloları, policy'leri, function'ları ve storage bucket'ları.
|
||||
- Environment variable değerleri.
|
||||
|
||||
Supabase tarafını yeni kuruyorsanız önce `supabase/setup.sql` dosyasını Supabase SQL Editor'da tek seferde çalıştırın. Terminal kullanıyorsanız aynı işlem şu komutla yapılabilir:
|
||||
|
||||
```bash
|
||||
psql "postgresql://postgres:[PASSWORD]@[HOST]:5432/postgres" -v ON_ERROR_STOP=1 -f supabase/setup.sql
|
||||
```
|
||||
|
||||
Gerekli env değerleri:
|
||||
|
||||
```env
|
||||
|
||||
@@ -22,6 +22,14 @@ Coolify deploy için hazır olması gerekenler:
|
||||
|
||||
Supabase tarafında tablo, policy, function ve storage bucket'ları hazır olmalıdır.
|
||||
|
||||
Yeni bir Supabase projesi hazırlıyorsanız `supabase/setup.sql` dosyasını tek seferde çalıştırabilirsiniz:
|
||||
|
||||
```bash
|
||||
psql "postgresql://postgres:[PASSWORD]@[HOST]:5432/postgres" -v ON_ERROR_STOP=1 -f supabase/setup.sql
|
||||
```
|
||||
|
||||
Supabase panelinden ilerlemek isterseniz aynı dosyanın tamamını SQL Editor'a yapıştırıp çalıştırmanız yeterli.
|
||||
|
||||
## Uygulama Oluşturma
|
||||
|
||||
Coolify içinde yeni bir application oluştururken:
|
||||
|
||||
@@ -20,6 +20,14 @@ Başlamadan önce şunlar hazır olmalı:
|
||||
- Supabase schema ve storage yapısı.
|
||||
- Ortam değişkenleri.
|
||||
|
||||
Supabase tarafı hazır değilse önce `supabase/setup.sql` dosyasını çalıştırın. Terminalden tek komutla kurmak için:
|
||||
|
||||
```bash
|
||||
psql "postgresql://postgres:[PASSWORD]@[HOST]:5432/postgres" -v ON_ERROR_STOP=1 -f supabase/setup.sql
|
||||
```
|
||||
|
||||
SQL Editor kullanıyorsanız `supabase/setup.sql` içeriğini komple yapıştırıp çalıştırabilirsiniz.
|
||||
|
||||
## Dokploy'da Uygulama Oluşturma
|
||||
|
||||
Dokploy içinde yeni bir uygulama oluştururken GitHub reposunu seçin. Uygulamayı Node.js/Next.js app olarak yapılandırın.
|
||||
|
||||
@@ -33,10 +33,10 @@ They must also be documented and registered in this file, but they should only b
|
||||
|
||||
## Applying The Ordered SQL
|
||||
|
||||
Use the migration helper from the repository root:
|
||||
For a fresh Supabase project, use the one-shot setup file from the repository root:
|
||||
|
||||
```bash
|
||||
DATABASE_URL='postgresql://postgres:password@host:5432/postgres' sh ./scripts/apply-migrations.sh
|
||||
psql "postgresql://postgres:[PASSWORD]@[HOST]:5432/postgres" -v ON_ERROR_STOP=1 -f supabase/setup.sql
|
||||
```
|
||||
|
||||
The helper applies missing queries from `0001` through `0011` in the order listed above and records completed migrations in `neta_internal.schema_migrations`. It uses local `psql` when available, otherwise it runs `psql` through Docker. After migrations, it sends `NOTIFY pgrst, 'reload schema'` so PostgREST can see new RPC functions without a manual restart.
|
||||
The setup file applies `0001` through `0011` in the order listed above. It does not include optional seed data. If you are changing the schema later, keep adding ordered files under `supabase/migrations/` and update this table.
|
||||
|
||||
Reference in New Issue
Block a user