Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new
Data / Files and data

Data

Files and data

Where your app may write, what is kept and what is wiped. SQLite, uploads and DATA_DIR.

While an app or bot runs, its code is read-only. There are two places it can write, and they behave differently.

What is kept

Place Kept For
/app/data Yes — across deploys and restarts Database files, uploads, sessions
/tmp No — wiped on every restart and deploy, 128 MB Scratch files
The code folder (/app) Not writable —

/app/data is the project’s own disk. Its path is also in the DATA_DIR variable; read it from there rather than hard-coding it.

If your repository has a data folder, the disk covers it: the files in it are not visible to the running app.

Projects that run from a Dockerfile or a ready image get the disk at /data, with DATA_DIR=/data.

SQLite lands on the disk by itself

A SQLite file whose name is written literally in the code is linked to the disk for you. For example:

  • sqlite3.connect('bot.db')
  • SQLAlchemy: sqlite:///app.db
  • better-sqlite3: new Database('app.db')

That file is written to /app/data and survives a deploy. If the name comes from a variable or a config file, the platform cannot see it; take the path from DATA_DIR instead.

Examples

Python, sqlite3:

import os, sqlite3

db = sqlite3.connect(os.path.join(os.environ["DATA_DIR"], "bot.db"))

An aiogram bot keeping its users in SQLite:

import os
import aiosqlite

DB = os.path.join(os.environ.get("DATA_DIR", "data"), "users.db")

async def save_user(user_id: int):
    async with aiosqlite.connect(DB) as db:
        await db.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY)")
        await db.execute("INSERT OR IGNORE INTO users VALUES (?)", (user_id,))
        await db.commit()

Node, better-sqlite3:

import path from 'node:path'
import Database from 'better-sqlite3'

const db = new Database(path.join(process.env.DATA_DIR ?? 'data', 'app.db'))

Prisma: add this to the project’s variables.

DATABASE_URL=file:/app/data/app.db

A folder for uploads:

const uploads = path.join(process.env.DATA_DIR, 'uploads')
fs.mkdirSync(uploads, { recursive: true })

Real data belongs in a database

The disk belongs to one app: no other service sees it, and it is not backed up. SQLite is fine for a small bot or a prototype. Once there are customers, orders or payments, open a PostgreSQL database: it has backups and several services can connect to it. For lots of images and large files, use an S3 bucket.

Got a question? — @livops_uz