The Brooklyn Rail Studio https://studio.brooklynrail.org
Powered by Directus https://directus.io/
To run the Brooklyn Rail Studio project locally on your computer, follow these steps:
- Clone the repository https://github.com/brooklynrail/studio.git
- Install the Docker Desktop App https://www.docker.com/products/docker-desktop/
- Open Docker
- In the terminal, run
docker compose up --build
-- this will take 3-4 mins while it builds the docker images from scratch, and installs the current schema. If the images are already built, you can start the container by runningdocker compose up
. - Visit http://localhost:8055
You will need to generate an API Token upon building Directus for the first time.
- Within the Directus App, go to User Directory
- Click on your profile
- Scroll down to Admin Options and generate a new token
- Copy the token
- Save the settings
- Paste the token at the top of your
.env
file
TOKEN_LOCAL="the-token-goes-here"
When Directus is built via Docker or via yarn build
, it uses this init.yaml
file to setup the content schema, specific fields, and field settings within Directus. https://github.com/brooklynrail/studio/blob/main/snapshots/init.yaml
When we make changes to the schema, it is essential that we update the init.yaml
file to reflect the most recent changes.
To update the schema:
- Go to the API viewer on the left side within the Directus App
- Click on Retrieve Schema Snapshot in the left sidebar
- In the QUERY-STRING PARAMETERS export box, click on
yaml
- click on the TRY button — this will generate the schema in
yaml
format - Copy the contents and paste them into the file
/snapshots/init.yaml
A few things to know about our migration:
- the current Rail database running on
mysql:5.7.42
, hosted in Google Cloud. - the current Rail database application is a very old PHP/Codeigniter site, hosted on GoDaddy.
- the content in the database is currently encoded in
Latin-1(ISO-8859-1)
- to update the encoding and export the content, we've created a number of custom APIs into the current Codeigniter site. These are designed to migrate everything into our schema, in Directus
- we are converting each node in these APIs to
UTF-8
fromLatin-1(ISO-8859-1)
(and hoping this works) - we have a number of NodeJS scripts that import all of the Rail content into Directus, one issue at a time.
- we are migrating everything to a
postgres
database, hosted on Directus Cloud
All of our migration scripts are located in the /sync
folder
Note: to use these scripts, you'll need to be running node 18
. Use nvm use 18
to set the node version.
-
Import the current Contributors (+8,100) —
node sync/createContributors.js
-
Import the current Sections (+35) —
node sync/createSections.js
-
Import All Issues (+245 issues) —
node sync/createSections.js
- Each issue has anywhere from 100-300 articles and 300-500 images
- There are +40,000 articles in total, and maybe around 100,000 image files
- we can modify this to import one issue at a time, if needed
-
Import all Ads (~1,000) —
node sync/createAds.js
- Issue + Articles https://brooklynrail.org/2023/12/api
- All Issues https://brooklynrail.org/api/issues/
- All Issues as list https://brooklynrail.org/api/issue-list
- All Contributors https://brooklynrail.org/api/contributors
- All Sections https://brooklynrail.org/api/sections
- All Ads https://brooklynrail.org/api/ads
Required settings for all image transformations.
promo-section
— 400x530promo-banner
— 632x192promo-thumb
— 120x120slideshow-image
— 1328x564featured-image
— 800x1058
via https://simplebackups.com/blog/docker-postgres-backup-restore-guide-with-examples/
docker exec -i studio-db /usr/bin/pg_dump \ -U postgres directus > postgres-backup.sql
docker exec studio-db /bin/bash \
-c "/usr/bin/pg_dump -U postgres directus" \
| gzip -9 > postgres-backup.sql.gz