Skip to content

Commit c497ec5

Browse files
authored
Merge pull request #44 from Zenfulcode/development
Almost complete project rewrite
2 parents 12540d0 + 40d91f6 commit c497ec5

251 files changed

Lines changed: 15276 additions & 25900 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
DB_HOST=localhost
2-
DB_PORT=5432
3-
DB_USER=
4-
DB_PASSWORD=
5-
DB_NAME=commercify
1+
# Database Configuration
2+
# For local development (SQLite)
3+
DB_DRIVER=sqlite
4+
DB_NAME=commercify.db
5+
6+
# For production (PostgreSQL) - uncomment and configure these when using PostgreSQL
7+
# DB_DRIVER=postgres
8+
# DB_HOST=localhost
9+
# DB_PORT=5432
10+
# DB_USER=postgres
11+
# DB_PASSWORD=postgres
12+
# DB_NAME=commercify
13+
# DB_SSL_MODE=disable
14+
15+
# Debug mode for database queries
16+
DB_DEBUG=false
617

718
AUTH_JWT_SECRET=your_jwt_secret
819

@@ -29,7 +40,6 @@ MOBILEPAY_CLIENT_ID=your_client_id
2940
MOBILEPAY_CLIENT_SECRET=your_client_secret
3041
MOBILEPAY_WEBHOOK_URL=https://your-site.com/api/webhooks/mobilepay
3142
MOBILEPAY_PAYMENT_DESCRIPTION=Commercify Store Purchase
32-
MOBILEPAY_MARKET=NOK
3343

3444
RETURN_URL=https://your-site.com/payment/complete
3545
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
.env.local
27+
.env.production
28+
29+
# SQLite database files
30+
*.db
31+
*.sqlite
32+
*.sqlite3
2633

2734
bin/
2835
commercify

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ RUN rm -f go.work go.work.sum
1414
# Build all three applications
1515
RUN go mod download
1616
RUN go build -o commercify cmd/api/main.go
17-
RUN go build -o commercify-migrate cmd/migrate/main.go
1817
RUN go build -o commercify-seed cmd/seed/main.go
1918

2019
# Create a minimal final image
@@ -27,16 +26,14 @@ RUN apk add --no-cache ca-certificates tzdata bash
2726

2827
# Copy the binaries from the builder stage
2928
COPY --from=builder /app/commercify /app/commercify
30-
COPY --from=builder /app/commercify-migrate /app/commercify-migrate
3129
COPY --from=builder /app/commercify-seed /app/commercify-seed
32-
COPY --from=builder /app/migrations /app/migrations
3330
COPY --from=builder /app/templates /app/templates
3431

3532
# Copy .env file if it exists (will be overridden by env_file in docker-compose)
3633
# COPY --from=builder /app/.env /app/
3734

3835
# Set executable permissions for all binaries
39-
RUN chmod +x /app/commercify /app/commercify-migrate /app/commercify-seed
36+
RUN chmod +x /app/commercify /app/commercify-seed
4037

4138
# Expose the port
4239
EXPOSE 6091

Makefile

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
.PHONY: help db-start db-stop db-restart db-logs db-clean migrate-up migrate-down seed-data build run test clean docker-build docker-build-tag docker-push docker-build-push
1+
.PHONY: help db-start db-stop db-restart db-logs db-clean seed-data build run test clean docker-build docker-build-tag docker-push docker-build-push dev-sqlite dev-postgres
22

33
# Default target
44
help: ## Show this help message
55
@echo "Available commands:"
66
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
77

8-
# Database commands
8+
# Development environment setup
9+
dev-postgres: ## Run the application locally with database
10+
@echo "Setting up PostgreSQL development environment..."
11+
@cp .env.production .env 2>/dev/null || true
12+
@echo "Environment configured for PostgreSQL. Starting application..."
13+
@echo "Starting database and waiting for it to be ready..."
14+
make db-start
15+
@sleep 3
16+
go run ./cmd/api
17+
18+
# Database commands (PostgreSQL)
919
db-start: ## Start PostgreSQL database container
1020
docker compose up -d postgres
1121

@@ -22,41 +32,40 @@ db-clean: ## Stop and remove PostgreSQL container and volumes
2232
docker compose down postgres
2333
docker volume rm commercify_postgres_data 2>/dev/null || true
2434

25-
# Migration commands
26-
migrate-up: ## Run database migrations up
27-
docker compose run --rm migrate -up
28-
29-
migrate-down: ## Run database migrations down
30-
docker compose run --rm migrate -down
31-
32-
migrate-status: ## Show migration status
33-
docker compose run --rm migrate -status
34-
3535
# Seed data
3636
seed-data: ## Seed database with sample data
3737
docker compose run --rm seed -all
3838

3939
# Application commands
4040
build: ## Build the application
4141
go build -o bin/api ./cmd/api
42-
go build -o bin/migrate ./cmd/migrate
4342
go build -o bin/seed ./cmd/seed
4443
go build -o bin/expire-checkouts ./cmd/expire-checkouts
4544

46-
run: db-start ## Run the application locally with database
47-
@echo "Starting database and waiting for it to be ready..."
48-
@sleep 3
45+
run:
46+
@echo "Setting up SQLite development environment..."
47+
@cp .env.local .env 2>/dev/null || true
48+
@echo "Environment configured for SQLite. Starting application..."
4949
go run ./cmd/api
5050

51-
run-docker: ## Run the entire application stack with Docker
51+
run-docker: ## Run the entire application stack with Docker (PostgreSQL)
5252
docker compose up -d
5353

54+
run-docker-sqlite: ## Run the application with Docker using SQLite
55+
docker compose -f docker-compose.local.yml up -d
56+
5457
stop-docker: ## Stop the entire application stack
5558
docker compose down
5659

60+
stop-docker-sqlite: ## Stop the SQLite application stack
61+
docker compose -f docker-compose.local.yml down
62+
5763
logs: ## Show application logs
5864
docker compose logs -f api
5965

66+
logs-sqlite: ## Show SQLite application logs
67+
docker compose -f docker-compose.local.yml logs -f api
68+
6069
# Docker image commands
6170
docker-build: ## Build Docker image
6271
docker build -t ghcr.io/zenfulcode/commercifygo:latest .
@@ -76,8 +85,9 @@ docker-push: ## Push Docker image to registry (use REGISTRY and TAG)
7685

7786
docker-build-push: docker-build-tag docker-push ## Build and push Docker image (use REGISTRY and TAG)
7887

79-
docker-dev-build: ## Build Docker image for development
80-
docker build -t ghcr.io/zenfulcode/commercifygo:dev .
88+
docker-dev-push: ## Build Docker image for development
89+
docker build -t ghcr.io/zenfulcode/commercifygo:v2-dev .
90+
docker push ghcr.io/zenfulcode/commercifygo:v2-dev
8191

8292
# Development commands
8393
test: ## Run tests
@@ -90,12 +100,21 @@ clean: ## Clean build artifacts
90100
rm -rf bin/
91101
go clean
92102

93-
# Database setup for development
94-
dev-setup: db-start migrate-up seed-data ## Setup development environment (start db, migrate, seed)
95-
@echo "Development environment ready!"
103+
# Database setup commands
104+
dev-setup: ## Setup development environment with PostgreSQL (start db, seed)
105+
make db-start
106+
@sleep 3
107+
make seed-data
108+
@echo "Development environment ready with PostgreSQL!"
109+
110+
dev-reset: db-clean db-start seed-data ## Reset PostgreSQL development environment
111+
@echo "Development environment reset with PostgreSQL!"
96112

97-
dev-reset: db-clean db-start migrate-up seed-data ## Reset development environment
98-
@echo "Development environment reset!"
113+
dev-reset-sqlite: ## Reset SQLite development environment
114+
@echo "Resetting SQLite development environment..."
115+
@rm -f commercify.db 2>/dev/null || true
116+
@cp .env.local .env 2>/dev/null || true
117+
@echo "SQLite database reset!"
99118

100119
# Format and lint
101120
fmt: ## Format Go code

cmd/api/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ func main() {
3434
}
3535

3636
// Connect to database
37-
db, err := database.NewPostgresConnection(cfg.Database)
37+
db, err := database.InitDB(cfg.Database)
3838
if err != nil {
3939
logger.Fatal("Failed to connect to database: %v", err)
4040
}
41-
defer db.Close()
42-
43-
// Run database migrations
44-
if err := database.RunMigrations(db, cfg.Database); err != nil {
45-
logger.Fatal("Failed to run database migrations: %v", err)
46-
}
41+
defer database.Close(db)
4742

4843
// Initialize API server
4944
server := api.NewServer(cfg, db, logger)

cmd/expire-checkouts/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func main() {
2727
}
2828

2929
// Connect to database
30-
db, err := database.NewPostgresConnection(cfg.Database)
30+
db, err := database.InitDB(cfg.Database)
3131
if err != nil {
3232
logger.Fatal("Failed to connect to database: %v", err)
3333
}
34-
defer db.Close()
34+
defer database.Close(db)
3535

3636
// Initialize dependency container
3737
diContainer := container.NewContainer(cfg, db, logger)

cmd/migrate/main.go

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

0 commit comments

Comments
 (0)