Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] chore(examples): Make store work in prod (switch to Postgres) #117

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/store/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## Getting Started

1. Setup your database
1. Ensure you have Postgres installed locally
2. Set the `DATABASE_URL` environment variable, something like this:

```
DATABASE_URL=postgresql://<your_computer_username>@localhost:5432/blitz-example-store
```

3. DB migrate

```
yarn blitz db migrate
```

2. Start the dev server
4. Start the dev server

```
yarn blitz start
Expand Down
166 changes: 0 additions & 166 deletions examples/store/app/pages/about.tsx

This file was deleted.

48 changes: 13 additions & 35 deletions examples/store/app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
import Head from 'next/head'
import {Link} from '@blitzjs/core'

const Home = () => (
<div className="container">
<Head>
<title>Create Next App</title>
<title>Blitz Example Store</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<main>
<h1 className="title">
Welcome to <a href="https://nextjs.org">Next.js!</a>
<h1 className="title" style={{marginBottom: 24}}>
Blitz Store Example
</h1>

<p className="description">
Get started by editing <code>pages/index.js</code>
<p>
<Link href="/products">
<a>View Static Public Product Listings</a>
</Link>
</p>
<p>
<Link href="/admin">
<a>View Dynamic Admin Section</a>
</Link>
</p>

<div className="grid">
<a href="https://nextjs.org/docs" className="card">
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className="card">
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a href="https://github.com/zeit/next.js/tree/master/examples" className="card">
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://zeit.co/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className="card">
<h3>Deploy &rarr;</h3>
<p>Instantly deploy your Next.js site to a public URL with ZEIT Now.</p>
</a>
</div>
</main>

<footer>
Expand Down Expand Up @@ -89,11 +72,6 @@ const Home = () => (
}

a {
color: inherit;
text-decoration: none;
}

.title a {
color: #0070f3;
text-decoration: none;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/store/app/products/pages/products/[handle].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ export const getStaticProps: GetStaticProps<StaticProps> = async (ctx) => {

return {
props: {product},
revalidate: 1,
}
}
export const getStaticPaths: GetStaticPaths = async () => {
const paths = (await getProducts()).map(({handle}) => ({params: {handle}}))
return {
paths,
fallback: false,
fallback: true,
}
}

const Page: BlitzPage<StaticProps> = function ({product}) {
if (!product) {
return <div>Building Page...</div>
}

return (
<div>
<h1>{product.name}</h1>
Expand Down
1 change: 1 addition & 0 deletions examples/store/app/products/pages/products/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const getStaticProps: GetStaticProps<StaticProps> = async () => {

return {
props: {products},
revalidate: 1,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# Migration `20200411130101-init`
# Migration `20200414170933-init`

This migration has been generated by Brandon Bayer at 4/11/2020, 1:01:01 PM.
This migration has been generated by Brandon Bayer at 4/14/2020, 5:09:33 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
CREATE TABLE "quaint"."User" (
"email" TEXT NOT NULL ,
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT ,
"role" TEXT ,
"storeId" INTEGER
CREATE TABLE "public"."User" (
"email" text NOT NULL ,
"id" SERIAL,
"name" text ,
"role" text ,
"storeId" integer ,
PRIMARY KEY ("id")
)

CREATE TABLE "quaint"."Product" (
"description" TEXT ,
"handle" TEXT NOT NULL ,
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT ,
"price" INTEGER
CREATE TABLE "public"."Product" (
"description" text ,
"handle" text NOT NULL ,
"id" SERIAL,
"name" text ,
"price" integer ,
PRIMARY KEY ("id")
)

CREATE UNIQUE INDEX "quaint"."User.email" ON "User"("email")
CREATE UNIQUE INDEX "User.email" ON "public"."User"("email")

CREATE UNIQUE INDEX "quaint"."Product.handle" ON "Product"("handle")
CREATE UNIQUE INDEX "Product.handle" ON "public"."Product"("handle")
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration ..20200411130101-init
migration ..20200414170933-init
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,30 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+datasource db {
+ provider = "sqlite"
+ url = "file:./db.sqlite"
+datasource postgresql {
+ provider = "postgresql"
+ url = env("DATABASE_URL")
+}
+
+generator client {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
provider = "sqlite"
datasource postgresql {
provider = "postgresql"
url = "***"
}

Expand Down
Loading