System Information
-
Strapi Version: 4.6.1
-
Operating System:
-
Database: Postgres
-
Node Version: 16
-
NPM Version: 8
-
Yarn Version:
I have deployed a Strapi admin-panel/backend on AWS ECR, using docker and kubernetes. My db is postgres(also on AWS). I am using develop as it is a staging env. I can create collections and singles, but for some reason they get deleted(the tables are gone from the database) and I don’t know why. I can see in my logs that following sql is executed:
sql: ‘delete from “admin_permissions” where (“id” = ?)’
sql: ‘delete from “strapi_core_store_settings” where (“id” = ?)’,
sql: ‘delete from “strapi_database_schema”’,
It may seem to happen when the server restarts, but I’m not 100% sure
How does your database.js file look 
Don’t use SQLITE in production / staging because when you delete or redeploy the container you get the issue you are having, so make sure it’s using an external database to make it persist.
I use postgres in staging/production, and my database.ts look like below:
export default ({ env }) => ({
connection: {
client: ‘postgres’,
connection: {
host: env(‘DATABASE_HOST’, ‘-----’),
port: env.int(‘DATABASE_PORT’, 5432),
database: env(‘DATABASE_NAME’, ‘postgres’),
user: env(‘DATABASE_USERNAME’, ‘user’),
password: env(‘DATABASE_PASSWORD’, ‘password’),
ssl: env.bool(‘DATABASE_SSL’, false),
},
debug: true,
},
},
});
Are you sure that it’s using this, because by seen the errors you are doing it sounds to me like it’s running in development mode and not production also then executing sqlite hence why you loose data.
Can’t I run in development mode and still use external database? the documention fro Strapi mentions that staging env uses develop command, no? I was also under the impression that you can’t create collections when runing in production mode? I’m pretty sure I saw the table in my postgres db after I created it. I have only configured a postgres database as mentioned above.
So it seems that it uses my postgres database.
Do you have a config/development/database.js
if so what was the content of it ? 
It is the same as the one I posted earlier.
export default ({ env }) => ({
connection: {
client: ‘postgres’,
connection: {
host: env(‘DATABASE_HOST’, ‘-----’),
port: env.int(‘DATABASE_PORT’, 5432),
database: env(‘DATABASE_NAME’, ‘postgres’),
user: env(‘DATABASE_USERNAME’, ‘user’),
password: env(‘DATABASE_PASSWORD’, ‘password’),
ssl: env.bool(‘DATABASE_SSL’, false),
},
debug: true,
},
},
});
That then looks correct, what is in your .env
file ?
HOST=0.0.0.0
PORT=1337
APP_KEYS=XPWkrXQc5AvCbz9XDPra5w==,bgymF/7WF+Mhi2GN4poRfg==,Zi0Ae3SQ7AnfE+7kD8d0MQ==,FACz+LoBhjxMZqGChah3vw==
API_TOKEN_SALT=I2da0sU/osJwA+xoszhBEQ==
ADMIN_JWT_SECRET=3B0V8IX6kcMCMKWD2HX7CQ==
JWT_SECRET=li1yXSuxVeNBPDLzEP2Frw==
DATABASE_HOST="****"
DATABASE_PORT=5432
DATABASE_NAME=“postgres”
DATABASE_USERNAME=“strapicms”
DATABASE_PASSWORD="*****"
Could you show me a screenshot of the folder tree structure of the app please 
Showing config and src please ?
Thank you for this, last question could you show me the Dockerfile you are using for development and or production.
I don’t think you are using the database in staging etc while on local are you ?
So when developing locally your not using your stage database ?
When I’m developing locally i have a local postgres database I use. 
Docker for dev:
FROM node:16-alpine
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./package-lock.json ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN npm install
WORKDIR /opt/app
COPY ./ .
RUN npm run build
EXPOSE 1337
CMD [“npm”, “run”, “develop”]
Docker for prod:
FROM node:16-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./package-lock.json ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN npm install --production
WORKDIR /opt/app
COPY ./ .
RUN npm run build
FROM node:16-alpine
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY --from=build /opt/app ./
EXPOSE 1337
CMD [“npm”, “run”,“start”]
That seems very correct to me.
Only thing I can think of then is that it uses sqlite under the hood or you are re-using the same database.
I don’t see why the database would just go a head and delete data and strapi would not do the same either.
When you redeploy it can drop tables if the schema.json
has changed but other then that it would not do anything like that.
I am not sure what you mean by ‘re-using the same database’?
I tried to set forceMigrations to false and now the behavior is a bit weird. My collections disappears from Strapi, BUT when I go and create them again, they show up in the content-manager AND they have the entries I made 2 days ago?
So the data remains in the database but is somehow not able to be displayed by strapi, until I create the collection again.
Are you using kubernetes or a cluster of Containers if I can ask ?
Yes I’m using Kubernetes and Amazon EKS 