Skip to content

Commit

Permalink
Create matchcodeio database and use it #224
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Jan 26, 2024
1 parent f8483ce commit 5a0a5e9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GET_SECRET_KEY=`base64 /dev/urandom | head -c50`
ENV_FILE=.env
# Customize with `$ make postgres PACKAGEDB_DB_PASSWORD=YOUR_PASSWORD`
PACKAGEDB_DB_PASSWORD=packagedb
SCANCODEIO_DB_PASSWORD=scancodeio
MATCHCODEIO_DB_PASSWORD=matchcodeio

# Use sudo for postgres, but only on Linux
UNAME := $(shell uname)
Expand Down Expand Up @@ -96,15 +96,15 @@ postgres:
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=packagedb packagedb
@$(MAKE) migrate

postgres_scancodeio:
postgres_matchcodeio:
@echo "-> Configure PostgreSQL database"
@echo "-> Create database user 'scancodeio'"
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb scancodeio || true
${SUDO_POSTGRES} psql -c "alter user scancodeio with encrypted password '${SCANCODEIO_DB_PASSWORD}';" || true
@echo "-> Drop 'scancodeio' database"
${SUDO_POSTGRES} dropdb scancodeio || true
@echo "-> Create 'scancodeio' database"
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=scancodeio scancodeio
@echo "-> Create database user 'matchcodeio'"
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb matchcodeio || true
${SUDO_POSTGRES} psql -c "alter user matchcodeio with encrypted password '${MATCHCODEIO_DB_PASSWORD}';" || true
@echo "-> Drop 'matchcodeio' database"
${SUDO_POSTGRES} dropdb matchcodeio || true
@echo "-> Create 'matchcodeio' database"
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=matchcodeio matchcodeio
${MATCHCODE_MANAGE} migrate

run:
Expand Down
6 changes: 3 additions & 3 deletions docker_matchcodeio.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
POSTGRES_DB=scancodeio
POSTGRES_USER=scancodeio
POSTGRES_PASSWORD=scancodeio
POSTGRES_DB=matchcodeio
POSTGRES_USER=matchcodeio
POSTGRES_PASSWORD=matchcodeio
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8

PACKAGEDB_DB_HOST=db
Expand Down
46 changes: 27 additions & 19 deletions matchcode_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,40 @@


INSTALLED_APPS += [
"clearcode",
"clearindex",
"matchcode",
"minecode",
"packagedb",
'clearcode',
'clearindex',
'matchcode',
'minecode',
'packagedb',
]

# Database

DATABASES.update(
{
'packagedb': {
'ENGINE': env.str('PACKAGEDB_DB_ENGINE', 'django.db.backends.postgresql'),
'HOST': env.str('PACKAGEDB_DB_HOST', 'localhost'),
'NAME': env.str('PACKAGEDB_DB_NAME', 'packagedb'),
'USER': env.str('PACKAGEDB_DB_USER', 'packagedb'),
'PASSWORD': env.str('PACKAGEDB_DB_PASSWORD', 'packagedb'),
'PORT': env.str('PACKAGEDB_DB_PORT', '5432'),
'ATOMIC_REQUESTS': True,
}
DATABASES = {
'default': {
'ENGINE': env.str('SCANCODEIO_DB_ENGINE', 'django.db.backends.postgresql'),
'HOST': env.str('SCANCODEIO_DB_HOST', 'localhost'),
'NAME': env.str('SCANCODEIO_DB_NAME', 'matchcodeio'),
'USER': env.str('SCANCODEIO_DB_USER', 'matchcodeio'),
'PASSWORD': env.str('SCANCODEIO_DB_PASSWORD', 'matchcodeio'),
'PORT': env.str('SCANCODEIO_DB_PORT', '5432'),
'ATOMIC_REQUESTS': True,
},
'packagedb': {
'ENGINE': env.str('PACKAGEDB_DB_ENGINE', 'django.db.backends.postgresql'),
'HOST': env.str('PACKAGEDB_DB_HOST', 'localhost'),
'NAME': env.str('PACKAGEDB_DB_NAME', 'packagedb'),
'USER': env.str('PACKAGEDB_DB_USER', 'packagedb'),
'PASSWORD': env.str('PACKAGEDB_DB_PASSWORD', 'packagedb'),
'PORT': env.str('PACKAGEDB_DB_PORT', '5432'),
'ATOMIC_REQUESTS': True,
}
)
}


DATABASE_ROUTERS = [
"matchcode_project.dbrouter.PackageDBRouter",
"matchcode_project.dbrouter.ScancodeIORouter",
'matchcode_project.dbrouter.PackageDBRouter',
'matchcode_project.dbrouter.ScancodeIORouter',
]

ROOT_URLCONF = 'matchcode_project.urls'

0 comments on commit 5a0a5e9

Please sign in to comment.