]> git.parisson.com Git - teleforma.git/commitdiff
First shot at switching to postgresql feature/postgres
authorGael Le Mignot <gael@pilotsystems.net>
Mon, 31 May 2021 07:07:31 +0000 (09:07 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Mon, 31 May 2021 07:07:31 +0000 (09:07 +0200)
app/bin/wait.sh
app/settings.py
docker-compose.yml
env/debug.env
requirements.txt
teleforma/management/commands/teleforma-convert-boolean-fields.py [new file with mode: 0644]

index e9331381613728915c231a16fc5aa241299e8888..0d92f08c5c2b28d70552d806f3120ff99d3e7a68 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-/srv/bin/misc/wait-for-it/wait-for-it.sh -h localhost -p $DB_PORT;
+/srv/bin/misc/wait-for-it/wait-for-it.sh -h $DB_HOST -p $DB_PORT;
index bcec29edd0140b9283aa3bc20f6fd6b68319cfe5..ba1903d6cc3e69abc987742d5f5c2148b695758c 100644 (file)
@@ -29,21 +29,21 @@ MANAGERS = ADMINS
 DATABASES = {
     'default': {
         # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'ENGINE': 'django.db.backends.mysql',
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
         # Or path to database file if using sqlite3.
-        'NAME': os.environ.get('MYSQL_DATABASE'),
+        'NAME': os.environ.get('POSTGRES_DATABASE'),
         # Not used with sqlite3.
-        'USER': os.environ.get('MYSQL_USER'),
+        'USER': os.environ.get('POSTGRES_USER'),
         # Not used with sqlite3.
-        'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
+        'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
         # Set to empty string for localhost. Not used with sqlite3.
-        'HOST': 'db',
+        'HOST': 'postgres',
         # Set to empty string for default. Not used with sqlite3.
         'PORT': '',
-        'OPTIONS': {'init_command': 'SET storage_engine=InnoDB', },
     }
 }
 
+
 # Local time zone for this installation. Choices can be found here:
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
 # although not all choices may be available on all operating systems.
@@ -336,3 +336,5 @@ def show_user_as(user):
 POSTMAN_SHOW_USER_AS = show_user_as
 
 #THUMBNAIL_FORCE_OVERWRITE = True
+
+ALLOWED_HOSTS = [ 'crfpa.dockdev.pilotsystems.net' ]
index 82fd7518dafb945c809bd9620a9cf90d46b76fb7..b6a664e5743623f3799b68f618ae43b5f476f686 100644 (file)
@@ -15,19 +15,21 @@ services:
     ports:
       - "8000:8000"
     links:
-      - db
+      - postgres
     env_file:
       - env/debug.env
 
-  db:
-    image: mariadb
+  postgres:
+    image: postgres
     env_file:
       - env/debug.env
+    environment:
+      PGDATA: /var/lib/postgresql/data/pgdata
     volumes:
+      - ./var/lib/postgresql:/var/lib/postgresql/data:rw
       - ./bin:/srv/bin
-      - ./var/lib/mysql/:/var/lib/mysql
-      - ./var/log/mysql/:/var/log/mysql
       - ./var/backup/:/srv/backup
+      - /etc/localtime:/etc/localtime:ro
 
   memcached:
       image: memcached:alpine
index 4131492b26b670b18d0499e8ba275a25ee5de023..3634c8f519e398006616ff4c8c427dc48b6e8315 100644 (file)
@@ -4,4 +4,9 @@ MYSQL_ROOT_PASSWORD=mysecretpassword
 MYSQL_DATABASE=teleforma
 MYSQL_USER=teleforma
 MYSQL_PASSWORD=mysecretpassword
-DB_PORT=3306
+DB_PORT=5432
+DB_HOST=postgres
+
+POSTGRES_PASSWORD=mysecretpassword
+POSTGRES_DATABASE=teleforma
+POSTGRES_USER=teleforma
index bec6974021262009287548f8eb99bbab4da58136..56d7f373dc2de2b9d31b1000fcfdbdcf1efc9a0e 100644 (file)
@@ -21,4 +21,5 @@ sorl-thumbnail==12.7.0
 unidecode==1.2.0
 xhtml2pdf==0.2.5
 xlrd==2.0.1
-xlwt==1.3.0
\ No newline at end of file
+xlwt==1.3.0
+psycopg2==2.8.6 
diff --git a/teleforma/management/commands/teleforma-convert-boolean-fields.py b/teleforma/management/commands/teleforma-convert-boolean-fields.py
new file mode 100644 (file)
index 0000000..fcbd33d
--- /dev/null
@@ -0,0 +1,18 @@
+from django.conf import settings
+from django.apps import apps
+from django.core.management.base import BaseCommand, CommandError
+import django.db.models as models
+
+class Command(BaseCommand):
+    help = "Issue SQL commands to fix boolean fields after MySQL migration"
+    admin_email = 'webmaster@parisson.com'
+
+    def handle(self, *args, **options):
+        for app, _ in apps.all_models.items():
+            app_models = apps.get_app_config(app).get_models()
+            for model in app_models:
+                table = model._meta.db_table
+                for field in model._meta.fields:
+                    if isinstance(field, models.BooleanField):
+                        field_name = field.column
+                        print(f"alter table {table} alter {field_name} type boolean using case when {field_name}=0 then false else true end;")