Skip to content

Commit

Permalink
Add support for an SQLite-based project
Browse files Browse the repository at this point in the history
  • Loading branch information
imankulov committed Mar 19, 2024
1 parent 9bac8d2 commit 7221131
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 2 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ repos:
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-case-conflict
- id: debug-statements
4 changes: 3 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"project_url": "https://github.com/{{ cookiecutter.author_github}}/{{ cookiecutter.project_slug }}",
"project_version": "0.1.0",

"database": ["postgresql", "sqlite"],

"postgresql_port": "5432",
"postgresql_version": "14",
"postgresql_version": "15",
"postgresql_user": "{{ cookiecutter.project_slug.replace('-', '_') }}",
"postgresql_password": "password",
"postgresql_database": "{{ cookiecutter.project_slug.replace('-', '_') }}",
Expand Down
7 changes: 7 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import subprocess as subp


DATABASE = "{{ cookiecutter.database }}"


def run():
"""Main entrypoint."""
if DATABASE == "sqlite":
# We don't need docker-compose.yml for sqlite
run_command("rm", "-f", "docker-compose.yml")

run_command("git", "init")
run_command("git", "add", ".")
run_command("pre-commit", "install")
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [push]
jobs:
build-test:
runs-on: ubuntu-latest
{% if cookiecutter.database == "postgresql" -%}
services:
postgres:
image: postgres:14
Expand All @@ -17,6 +18,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
{%- endif %}
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ ALLOWED_HOSTS=*

# See the URL format in the documentation:
# https://django-environ.readthedocs.io/en/latest/#supported-types
{% if cookiecutter.database == "postgres" -%}
DATABASE_URL=psql://{{ cookiecutter.postgresql_user }}:{{ cookiecutter.postgresql_password }}@127.0.0.1:{{ cookiecutter.postgresql_port }}/{{ cookiecutter.postgresql_database }}
{% elif cookiecutter.database == "sqlite" -%}
DATABASE_URL=sqlite:///db.sqlite3
{% endif -%}

# Sentry settings. Create a new free account at https://sentry.io, start a new
# project, and copy the Sentry DSN. An Empty Sentry DSN is acceptable and
Expand Down
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ ALLOWED_HOSTS=*

# See the URL format in the documentation:
# https://django-environ.readthedocs.io/en/latest/#supported-types
{% if cookiecutter.database == "postgres" -%}
DATABASE_URL=psql://{{ cookiecutter.postgresql_user }}:{{ cookiecutter.postgresql_password }}@postgres:5432/{{ cookiecutter.postgresql_database }}
{% elif cookiecutter.database == "sqlite" -%}
DATABASE_URL=sqlite:///db.sqlite3
{% endif -%}

# Sentry settings. Create a new free account at https://sentry.io, start a new
# project, and copy the Sentry DSN. An Empty Sentry DSN is acceptable and
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ python = "~{{ cookiecutter.python_version }}"
django = "^5.0.3"
django-environ = "^0.11.2"
django-extensions = "^3.2.3"
{% if cookiecutter.database == "postgresql" -%}
psycopg = "^3.1.18"
{%- endif %}
sentry-sdk = "^1.42.0"
gunicorn = "^21.2.0"
whitenoise = "^6.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
{% if cookiecutter.database == "postgresql" -%}
"django.contrib.postgres",
{%- endif %}
"django_extensions",
]

Expand Down

0 comments on commit 7221131

Please sign in to comment.