switched from sqlite to postgres

This commit is contained in:
afanasyev.aa 2025-04-06 00:26:30 +09:00
parent 8225b18a2a
commit 94501bf986
22 changed files with 80 additions and 143 deletions

Binary file not shown.

View file

@ -1,6 +1,9 @@
# Generated by Django 5.1.7 on 2025-03-15 08:54 # Generated by Django 4.2.20 on 2025-04-05 15:24
from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -8,15 +11,53 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Todo', name='Prediction',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('result', models.JSONField()),
('deleted_at', models.DateTimeField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='Satellite',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
],
),
migrations.CreateModel(
name='UserPrediction',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)), ('created_at', models.DateTimeField()),
('completed', models.BooleanField(default=False)), ('prediction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.prediction')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='TelemetryPacket',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('timestamp', models.BigIntegerField()),
('lat', models.FloatField()),
('lon', models.FloatField()),
('alt', models.FloatField()),
('payload', models.JSONField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('satellite', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='telemetry', to='api.satellite')),
], ],
), ),
] ]

View file

@ -1,46 +0,0 @@
# Generated by Django 5.1.7 on 2025-03-31 10:14
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Prediction',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('result', models.JSONField()),
('deleted_at', models.DateTimeField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
],
),
migrations.CreateModel(
name='UserPrediction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('prediction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.prediction')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.user')),
],
options={
'unique_together': {('user', 'prediction')},
},
),
migrations.DeleteModel(
name='Todo',
),
]

View file

@ -1,30 +0,0 @@
# Generated by Django 5.1.7 on 2025-04-05 10:40
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0002_prediction_user_userprediction_delete_todo'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AlterUniqueTogether(
name='userprediction',
unique_together=set(),
),
migrations.AlterField(
model_name='userprediction',
name='created_at',
field=models.DateTimeField(),
),
migrations.AlterField(
model_name='userprediction',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View file

@ -1,35 +0,0 @@
# Generated by Django 5.1.7 on 2025-04-05 13:30
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_alter_userprediction_unique_together_and_more'),
]
operations = [
migrations.CreateModel(
name='Satellite',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='TelemetryPacket',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('timestamp', models.BigIntegerField()),
('lat', models.FloatField()),
('lon', models.FloatField()),
('alt', models.FloatField()),
('payload', models.JSONField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('satellite', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='telemetry', to='api.satellite')),
],
),
]

Binary file not shown.

View file

@ -1,21 +1,30 @@
version: '3.9'
services: services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- .:/app
depends_on:
- db
db: db:
image: postgres:14 image: postgres:14
environment: environment:
POSTGRES_DB: testapi POSTGRES_DB: mydb
POSTGRES_USER: postgres POSTGRES_USER: myuser
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: mypass
volumes:
- postgres_data:/var/lib/postgresql/data
ports: ports:
- "5432:5432" - "5432:5432"
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
environment:
- DB_NAME=mydb
- DB_USER=myuser
- DB_PASSWORD=mypass
- DB_HOST=db
- DB_PORT=5432
volumes:
postgres_data:

View file

@ -4,3 +4,5 @@ djangorestframework-simplejwt
psycopg2-binary psycopg2-binary
drf-spectacular drf-spectacular
requests requests
django-cors-headers

View file

@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
""" """
from pathlib import Path from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
@ -42,6 +42,7 @@ INSTALLED_APPS = [
'drf_spectacular', 'drf_spectacular',
'corsheaders', 'corsheaders',
'api.apps.ApiConfig', 'api.apps.ApiConfig',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -89,21 +90,16 @@ WSGI_APPLICATION = 'testapi.wsgi.application'
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases # https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = { DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': 'drfapi', # Your database name
# 'USER': 'postgres', # Your PostgreSQL username
# 'PASSWORD': '1235', # Your PostgreSQL password
# 'HOST': 'localhost', # Or your DB server's IP
# 'PORT': '5432', # Default PostgreSQL port
# }
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': os.environ.get("DB_NAME", "drfapi"),
'USER': os.environ.get("DB_USER", "postgres"),
'PASSWORD': os.environ.get("DB_PASSWORD", "1235"),
'HOST': os.environ.get("DB_HOST", "localhost"),
'PORT': os.environ.get("DB_PORT", "5432"),
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators