Prerequisites:
- Ensure you're logged in to Github and then click "Use this template" to create your own instance of the repository. And then clone your copy of the repository to your local machine to make changes.
- Install Docker
- Install Node 14 or more recent version.
There are periodic updates to the base image as more functionality is added to the framework.
Anytime the base image changes (compare the top line in develop.Dockerfile
in the repository to your copy ), you should rebuild the image by running npm run rebuild-image
so as to not be stuck with an old image and not see the changes from the new version.
A list of available images can be seen by running the following command: docker image ls
. If you see an image with repository {container-name}_app
e.g. ent-starter_app
that's from a couple weeks or months ago after upgrading the base image, that's the issue you're running into.
There are 3 different supported ways to store data:
- Run
createdb ent-starter
(replace with name of your app) to create your database - update db credentials in file
docker-compose.dev.yml
by changingDB_CONNECTION_STRING
environment variable - Run
npm install
to install dependencies - Run
npm run codegen
after making any changes to the schema - Make sure to run
npm run compile
after making any changes to the code and before runningnpm start
Example schema change:
// src/schema/user_schema.ts
// this adds a User object with a firstName and lastName
import { EntSchema, StringType } from "@snowtop/ent";
const UserSchema = new EntSchema({
fields: {
firstName: StringType(),
lastName: StringType(),
},
});
export default UserSchema;
For a full intro, check out the docs.
Instead of installing Postgres and having to deal with a local install, you can use the postgres
image. Follow these steps to get started:
- uncomment out the section in
docker-compose-dev.yml
referring to thedb
service. Note that indentation inyml
files matters. - change the
DB_CONNECTION_STRING
line in the environment section of theapp
service toDB_CONNECTION_STRING=postgres://postgres:postgres@db/ent-starter
(or name of your app) - if you used a different database, update
POSTGRES_DB
environment variable to database - if you changed your project name, update
container_name
toname_of_project
- update
.gitignore
to addpostgres_data
so as to not check in the postgres files. - Add
psql
as a script to thescripts
section ofpackage.json
with valuedocker-compose -f docker-compose.dev.yml run --rm db psql ent-starter -h db -U postgres
to make it easy to query the database. - Add
background
as a script to thescripts
section ofpackage.json
with valuedocker-compose -f docker-compose.dev.yml up -d
to run in detached mode since some of the commands require the database to be available and listening to connections before they can succeed. - Run
npm run background
to start the database in the background. - Run
npm install
to install dependencies - Run
npm run psql
to connect to database. Seems to be required to have the connection to database consistently work. - Run
npm run codegen
after making any changes to the schema - Make sure to run
npm run compile
after making any changes to the code and before runningnpm start
Example schema change:
// src/schema/user_schema.ts
// this adds a User object with a firstName and lastName
import { EntSchema, StringType } from "@snowtop/ent";
const UserSchema = new EntSchema({
fields: {
firstName: StringType(),
lastName: StringType(),
},
});
export default UserSchema;
When done, run docker container ls | grep ent-starter | cut -d " " -f 1 | xargs docker stop
to stop all containers.
- Need to run
npm install better-sqlite3
to install sqlite dependency. - Add
sqlite-init
to thescripts
section of package.json with valuerm -rf node_modules && docker-compose -f docker-compose.dev.yml run --rm app npm install
- Run
npm run sqlite-init
to initialize things/install dependencies. Anytime a new dependency is added, have to runnpm run sqlite-init
to install in the container. - change the
DB_CONNECTION_STRING
line in the environment section of theapp
service toDB_CONNECTION_STRING=sqlite:///ent-starter.db
- Run
npm run codegen
after making any changes to the schema - Make sure to run
npm run compile
after making any changes to the code and before runningnpm start
Example schema change:
// src/schema/user_schema.ts
// this adds a User object with a firstName and lastName
import { EntSchema, StringType } from "@snowtop/ent";
const UserSchema = new EntSchema({
fields: {
firstName: StringType(),
lastName: StringType(),
},
});
export default UserSchema;