Skip to content

Commit 0db609b

Browse files
Merge pull request #239 from max-programming/migrate-from-xata
Migrate from Xata to Postgres
2 parents 27679ca + b5b503d commit 0db609b

31 files changed

+4350
-2686
lines changed

.env.example

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
# Database
2+
DATABASE_URL="" # PostgreSQL connection string
3+
# For Docker Compose: postgresql://hacktoberfest:hacktoberfest123@localhost:5432/hacktoberfest
4+
# For cloud providers: copy the connection string from your provider
5+
6+
# Authentication
17
AUTH_SECRET="" # A random string
28
AUTH_URL="" # Should be http://localhost:3000 for local development
39
AUTH_GITHUB_ID=""
410
AUTH_GITHUB_SECRET=""
5-
XATA_API_KEY=""
6-
XATA_BRANCH="" # Default should be "main"
11+
AUTH_DRIZZLE_URL="$DATABASE_URL" # Should be the same as DATABASE_URL
712

13+
# Optional
814
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME="" # Optional
9-
NEXT_PUBLIC_ANALYTICS_WEBSITE_ID="" # Optional
15+
NEXT_PUBLIC_ANALYTICS_WEBSITE_ID="" # Optional

CONTRIBUTING.md

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,59 +42,79 @@ To use GitHub authentication in the project, you need to create a GitHub OAuth a
4242
6. On the next page, you'll see your Client ID. Click "Generate a new client secret" to create your Client Secret.
4343
7. Copy the Client ID and Client Secret to your `.env.local` file.
4444

45-
## Setting Up Xata
45+
## Setting Up the Database
4646

47-
Xata is used as the database for this project. Follow these steps to set it up:
47+
This project uses PostgreSQL as the database. You have several options for setting up the database:
4848

49-
1. Sign up for a Xata account at https://lite.xata.io/
50-
2. Create a new workspace and database from Xata dashboard
51-
3. Install the Xata CLI globally:
49+
### Option 1: Docker Compose (Recommended)
5250

53-
```sh
54-
npm install -g "@xata.io/cli@latest"
55-
```
51+
The easiest way to get started is using Docker Compose, which will set up a PostgreSQL database with simple credentials:
5652

57-
4. Authenticate with Xata:
53+
1. Start the PostgreSQL database:
5854

5955
```sh
60-
xata auth login
56+
docker compose up -d
6157
```
6258

63-
5. Initialize the database:
59+
> Use `docker-compose` if you are on an older version of Docker and the above command does not work.
6460
65-
```sh
66-
xata init
67-
```
61+
2. Wait for the database to be ready (you can check with `docker compose ps`)
6862

69-
5. Upload the database schema:
63+
3. Run database migrations:
7064

7165
```sh
72-
xata schema upload db-schema.json
66+
pnpm drizzle-kit migrate
7367
```
7468

75-
6. Generate the Xata client:
69+
The database will be available at `localhost:5432` with these credentials:
7670

77-
```sh
78-
xata codegen
79-
```
71+
- Database: `hacktoberfest`
72+
- Username: `hacktoberfest`
73+
- Password: `hacktoberfest123`
74+
75+
### Option 2: Local PostgreSQL Installation
76+
77+
If you prefer to install PostgreSQL locally:
78+
79+
1. Install PostgreSQL on your system
80+
2. Create a database named `hacktoberfest`
81+
3. Create a user `hacktoberfest` with password `hacktoberfest123`
82+
4. Grant all privileges on the database to the user
83+
84+
### Option 3: Cloud Database Providers
85+
86+
You can also use cloud database providers like:
87+
88+
- **Neon** (https://neon.tech/) - Free tier available
89+
- **Supabase** (https://supabase.com/) - Free tier available
90+
- **Railway** (https://railway.app/) - Free tier available
91+
- **PlanetScale** (https://planetscale.com/) - Free tier available
92+
93+
Simply create a PostgreSQL database and copy the connection string.
8094

8195
## Environment Variables
8296

83-
Create a `.env.local` file in the root of the project and add the following variables:
97+
Create a `.env` file in the root of the project and add the following variables:
8498

8599
```sh
100+
# Database
101+
DATABASE_URL="" # PostgreSQL connection string
102+
# For Docker Compose: postgresql://hacktoberfest:hacktoberfest123@localhost:5432/hacktoberfest
103+
# For cloud providers: copy the connection string from your provider
104+
105+
# Authentication
86106
AUTH_SECRET="" # A random string
87107
AUTH_URL="" # Should be http://localhost:3000 for local development
88108
AUTH_GITHUB_ID=""
89109
AUTH_GITHUB_SECRET=""
90-
XATA_API_KEY=""
91-
XATA_BRANCH="" # Default should be "main"
110+
AUTH_DRIZZLE_URL="$DATABASE_URL" # Should be the same as DATABASE_URL
92111

112+
# Optional
93113
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME="" # Optional
94114
NEXT_PUBLIC_ANALYTICS_WEBSITE_ID="" # Optional
95115
```
96116

97-
Make sure to fill in the required values for each variable. The `AUTH_SECRET` should be a random string, and `AUTH_URL` should be set to `http://localhost:3000` for local development. The `XATA_BRANCH` should typically be set to "main" unless you're using a different branch.
117+
Make sure to fill in the required values for each variable. The `AUTH_SECRET` should be a random string, and `AUTH_URL` should be set to `http://localhost:3000` for local development. The `DATABASE_URL` should point to your PostgreSQL database.
98118

99119
Remember to remove env variables that are optional and you are empty, they will cause validation errors
100120

db-schema.json

Lines changed: 0 additions & 240 deletions
This file was deleted.

docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "3.8"
2+
3+
services:
4+
postgres:
5+
image: postgres:alpine
6+
container_name: hacktoberfest-postgres
7+
restart: unless-stopped
8+
environment:
9+
POSTGRES_DB: hacktoberfest
10+
POSTGRES_USER: hacktoberfest
11+
POSTGRES_PASSWORD: hacktoberfest123
12+
ports:
13+
- "5432:5432"
14+
volumes:
15+
- postgres_data:/var/lib/postgresql/data
16+
healthcheck:
17+
test: ["CMD-SHELL", "pg_isready -U hacktoberfest -d hacktoberfest"]
18+
interval: 10s
19+
timeout: 5s
20+
retries: 5
21+
22+
volumes:
23+
postgres_data:

0 commit comments

Comments
 (0)