# Getting It Running

# Introduction

In this page, you will use the tooling you installed from the previous page to get Alexandria and its dependencies installed on your computer.

# Prerequisites

Environment Setup
../environment_setup/

# The App

We'll start by cloning the repository to your machine in your home directory.

cd ~
git clone git@github.com:AlexandriaILS/Alexandria.git

Once that completes, cd (change directory) into the new folder:

cd Alexandria

Now we're inside the project directory. Since we installed Poetry earlier, we can use it to install the dependencies for Alexandria. This will take a minute or two.

poetry install

Activate our new Python environment:

poetry shell

Create a new file here called local_settings.py -- you'll use this to override any settings you need while working on Alexandria. More on that later!

touch local_settings.py

Open the file in your preferred editor and paste the following lines into it as your starting point:

import better_exceptions

from alexandria.settings.local import *

# trust me, this will make your life better.
better_exceptions.MAX_LENGTH = None
# Use this file when developing locally -- it has some helpful additions which
# change how the server runs.
DEBUG = True

ALLOWED_HOSTS = ['*']
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    }
}

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'alexandria',
        'USER': 'alexandria',
        'PASSWORD': 'asdf',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
        'alexandria': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG')
        }
    },
}

# uncomment this when working on queued jobs to send them to the browser instead
# for debugging
# LIGHTWEIGHT_QUEUE_BACKEND = 'django_lightweight_queue.backends.debug_web.DebugWebBackend'

MIDDLEWARE = ["alexandria.middleware.BetterExceptionsMiddleware"] + MIDDLEWARE

Any setting specified here will override the setting in alexandria/settings/base.py without having to change anything in that file! It's a great way to test whatever you want without having to worry about undoing your changes.

# The Database

Alexandria requires PostgreSQL, a free and open source database, to function. We rely heavily on the fantastic features provided, so you will need to have an instance of Postgres running before you can bring up Alexandria locally. We use Docker to make it easily accessible and controllable.

All the initial setup commands are built into the Makefile, so download and start the Postgres Docker image:

make db_up

Once it finishes, set up the database by running the configuration command:

make db_setup

Now that it's set up, write our database schema to it by running:

make migrate

Since we're doing this for development purposes, now the database is ready for writing actual data. Alexandria includes all 67,000 titles currently on Project Gutenberg and we use these titles as our test data. Run the below command to import all the data:

make dev_data

Congratulations! You now have a local copy of Alexandria and a running database ready to interact with! Go to the next page to learn how to interact with your new install.