前端技术之:Prisma Demo服务部署过程记录
admin
2023-02-13 17:00:06
0次

安装前提条件:

1、已经安装了docker运行环境

2、以下命令执行记录发生在MackBook环境

3、已经安装了PostgreSQL(我使用的是11版本)

4、Node开发运行环境可以正常工作


首先需要通过Node包管理器安装Prisma工具:

npm install -g prisma


然后,创建并初始化prisma项目:

prisma init prisma-study

? Set up a new Prisma server or deploy to an existing server? (Use arrow keys)

                        

  You can set up Prisma for local development (based on docker-compose)

❯ Use existing database      Connect to existing database

  Create new database        Set up a local database using Docker

                        

  Or deploy to an existing Prisma server:

  Demo server                Hosted demo environment incl. database (requires login)

  Use other server           Manually provide endpoint of a running Prisma server


选择使用已存在的数据库(Use existing database)后,回车确认选择。


? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to?

  MySQL             MySQL compliant databases like MySQL or MariaDB

❯ PostgreSQL        PostgreSQL database


移动上下箭头键盘按键,选择PostgreSQL后,再次回车确认选择。


? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? (Use arrow keys)

❯ No

  Yes (experimental - Prisma migrations not yet supported)

  

Warning: Introspecting databases with existing data is currently an experimental feature. If you find any issues, please report them here: https://github.co

m/prisma/prisma/issues


提示是否在选择的数据库中包含已存在数据。因为是一个新库,所以默认选择No,然后回车确认。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host (localhost)


输入数据库的主机地址(注意,因为prisma会运行在docker中,所以,这儿需要配置宿主机IP,在类Linux系统上可以通过ifconfig命令来获取IP)。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.111.152.242

? Enter database port (5432)


回车确认使用默认的Postgres数据库的端口。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user


输入数据库的用户名后回车确认。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user postgres

? Enter database password

输入数据库用户对应的密码后回车确认。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user postgres

? Enter database password study

? Enter database name


输入使用的数据库名称后回车。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user postgres

? Enter database password study

? Enter database name study

? Use SSL? (Y/n)


提示是否使用安全的网络协议,这里选择不使用(输入n后回车)。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user postgres

? Enter database password study

? Enter database name study

? Use SSL? No

Connecting to database 18ms

? Select the programming language for the generated Prisma client

  Prisma TypeScript Client

  Prisma Flow Client

❯ Prisma JavaScript Client

  Prisma Go Client

  Don't generate

这里选择产生JavaScript客户端脚本(Prisma JavaScript Client)。

? Set up a new Prisma server or deploy to an existing server? Use existing database

? What kind of database do you want to deploy to? PostgreSQL

? Does your database contain existing data? No

? Enter database host 10.xxx.xxx.xxx(此处为你的docker宿主机IP)

? Enter database port 5432

? Enter database user postgres

? Enter database password study

? Enter database name study

? Use SSL? No

Connecting to database 18ms

? Select the programming language for the generated Prisma client Prisma JavaScript Client

Created 3 new files:                                                                          

  prisma.yml          Prisma service definition

  datamodel.prisma    GraphQL SDL-based datamodel (foundation for database)

  docker-compose.yml  Docker configuration file

Next steps:

  1. Open folder: cd prisma-study

  2. Start your Prisma server: docker-compose up -d

  3. Deploy your Prisma service: prisma deploy

  4. Read more about Prisma server:

     http://bit.ly/prisma-server-overview

Generating schema... 20ms

Saving Prisma Client (JavaScript) at /Users/chunrong.liu/dev/study/prisma-study/generated/prisma-client/


至此,Prisma项目创建并初始化完毕。

接下来按昭Next steps下面的步骤提示执行后续操作。

通过以下命令切换当前目录至刚创建的项目目录(prisma-study)中。

cd prisma-study/


通过docker编排命令在docker中运行prisma服务器。

docker-compose up -d


执行后命令行提示如下:

Creating prisma-study_prisma_1 … done

此时服务运行成功。


通过以下命令部署prisma服务。

$ prisma deploy

Creating stage default for service default ✔

Deploying service `default` to stage `default` to server `local` 476ms

Changes:

  User (Type)

  + Created type `User`

  + Created field `id` of type `GraphQLID!`

  + Created field `name` of type `String!`

  + Created field `updatedAt` of type `DateTime!`

  + Created field `createdAt` of type `DateTime!`

Applying changes 1.2s

Your Prisma GraphQL database endpoint is live:

  HTTP:  http://localhost:4466

  WS:    ws://localhost:4466

用流程器打开http://localhost:4466/链接地址,可以看到如下的UI界面。

前端技术之:Prisma Demo服务部署过程记录

运行如下命令可以看到演练数据:

$ prisma playground

Serving playground at http://localhost:3000/playground


此时会自动打开浏览器,并显示如下界面:

前端技术之:Prisma Demo服务部署过程记录

关于数据库无法连接的问题:

https://blog.csdn.net/liuchunming033/article/details/44810899

官方参考资料地址:

https://www.prisma.io/docs/quickstart/


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...