-
-
Save psychemedia/8fa117e34c62b7f80b6c595b8ba4f488 to your computer and use it in GitHub Desktop.
Example of docker-compose / Digital Ocean workbench config for running Jupyter notebooks, PostgresDB and Agensgraph db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create a default token/password for Jupyter notebook | |
JUPYTER_TOKEN=letmein |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# PostgreSQL Demo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%load_ext sql" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'Connected: postgres@postgres'" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%sql postgresql://postgres:changeme@agensgraph_postgres_container/postgres" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://postgres:***@agensgraph_postgres_container/postgres\n", | |
"3 rows affected.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<table>\n", | |
" <tr>\n", | |
" <th>datname</th>\n", | |
" <th>datdba</th>\n", | |
" <th>encoding</th>\n", | |
" <th>datcollate</th>\n", | |
" <th>datctype</th>\n", | |
" <th>datistemplate</th>\n", | |
" <th>datallowconn</th>\n", | |
" <th>datconnlimit</th>\n", | |
" <th>datlastsysoid</th>\n", | |
" <th>datfrozenxid</th>\n", | |
" <th>datminmxid</th>\n", | |
" <th>dattablespace</th>\n", | |
" <th>datacl</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>postgres</td>\n", | |
" <td>10</td>\n", | |
" <td>6</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" <td>-1</td>\n", | |
" <td>13066</td>\n", | |
" <td>562</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>template1</td>\n", | |
" <td>10</td>\n", | |
" <td>6</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" <td>-1</td>\n", | |
" <td>13066</td>\n", | |
" <td>562</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>{=c/postgres,postgres=CTc/postgres}</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>template0</td>\n", | |
" <td>10</td>\n", | |
" <td>6</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>en_US.utf8</td>\n", | |
" <td>True</td>\n", | |
" <td>False</td>\n", | |
" <td>-1</td>\n", | |
" <td>13066</td>\n", | |
" <td>562</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>{=c/postgres,postgres=CTc/postgres}</td>\n", | |
" </tr>\n", | |
"</table>" | |
], | |
"text/plain": [ | |
"[('postgres', 10, 6, 'en_US.utf8', 'en_US.utf8', False, True, -1, 13066, '562', '1', 1663, None),\n", | |
" ('template1', 10, 6, 'en_US.utf8', 'en_US.utf8', True, True, -1, 13066, '562', '1', 1663, '{=c/postgres,postgres=CTc/postgres}'),\n", | |
" ('template0', 10, 6, 'en_US.utf8', 'en_US.utf8', True, False, -1, 13066, '562', '1', 1663, '{=c/postgres,postgres=CTc/postgres}')]" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"SELECT * from pg_database" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Agensgraph Demo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'Connected: agens@postgres'" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%sql postgresql://agens:agens@agensgraph_agens_container/postgres" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"4 rows affected.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<table>\n", | |
" <tr>\n", | |
" <th>datname</th>\n", | |
" <th>datdba</th>\n", | |
" <th>encoding</th>\n", | |
" <th>datcollate</th>\n", | |
" <th>datctype</th>\n", | |
" <th>datistemplate</th>\n", | |
" <th>datallowconn</th>\n", | |
" <th>datconnlimit</th>\n", | |
" <th>datlastsysoid</th>\n", | |
" <th>datfrozenxid</th>\n", | |
" <th>datminmxid</th>\n", | |
" <th>dattablespace</th>\n", | |
" <th>datacl</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>postgres</td>\n", | |
" <td>10</td>\n", | |
" <td>0</td>\n", | |
" <td>C</td>\n", | |
" <td>C</td>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" <td>-1</td>\n", | |
" <td>12420</td>\n", | |
" <td>550</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>agens</td>\n", | |
" <td>10</td>\n", | |
" <td>0</td>\n", | |
" <td>C</td>\n", | |
" <td>C</td>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" <td>-1</td>\n", | |
" <td>12420</td>\n", | |
" <td>550</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>template1</td>\n", | |
" <td>10</td>\n", | |
" <td>0</td>\n", | |
" <td>C</td>\n", | |
" <td>C</td>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" <td>-1</td>\n", | |
" <td>12420</td>\n", | |
" <td>550</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>{=c/agens,agens=CTc/agens}</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>template0</td>\n", | |
" <td>10</td>\n", | |
" <td>0</td>\n", | |
" <td>C</td>\n", | |
" <td>C</td>\n", | |
" <td>True</td>\n", | |
" <td>False</td>\n", | |
" <td>-1</td>\n", | |
" <td>12420</td>\n", | |
" <td>550</td>\n", | |
" <td>1</td>\n", | |
" <td>1663</td>\n", | |
" <td>{=c/agens,agens=CTc/agens}</td>\n", | |
" </tr>\n", | |
"</table>" | |
], | |
"text/plain": [ | |
"[('postgres', 10, 0, 'C', 'C', False, True, -1, 12420, '550', '1', 1663, None),\n", | |
" ('agens', 10, 0, 'C', 'C', False, True, -1, 12420, '550', '1', 1663, None),\n", | |
" ('template1', 10, 0, 'C', 'C', True, True, -1, 12420, '550', '1', 1663, '{=c/agens,agens=CTc/agens}'),\n", | |
" ('template0', 10, 0, 'C', 'C', True, False, -1, 12420, '550', '1', 1663, '{=c/agens,agens=CTc/agens}')]" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"SELECT * from pg_database" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'Connected: agens@agens'" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%sql postgresql://agens:agens@agensgraph_container/agens" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"2 rows affected.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<table>\n", | |
" <tr>\n", | |
" <th>schemaname</th>\n", | |
" <th>tablename</th>\n", | |
" <th>tableowner</th>\n", | |
" <th>tablespace</th>\n", | |
" <th>hasindexes</th>\n", | |
" <th>hasrules</th>\n", | |
" <th>hastriggers</th>\n", | |
" <th>rowsecurity</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>agens_graph</td>\n", | |
" <td>ag_vertex</td>\n", | |
" <td>agens</td>\n", | |
" <td>None</td>\n", | |
" <td>True</td>\n", | |
" <td>False</td>\n", | |
" <td>False</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <td>agens_graph</td>\n", | |
" <td>ag_edge</td>\n", | |
" <td>agens</td>\n", | |
" <td>None</td>\n", | |
" <td>True</td>\n", | |
" <td>False</td>\n", | |
" <td>False</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
"</table>" | |
], | |
"text/plain": [ | |
"[('agens_graph', 'ag_vertex', 'agens', None, True, False, False, False),\n", | |
" ('agens_graph', 'ag_edge', 'agens', None, True, False, False, False)]" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"SELECT * FROM pg_catalog.pg_tables WHERE schemaname !='pg_catalog' AND schemaname !='information_schema';" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"Done.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"CREATE EXTENSION IF NOT EXISTS file_fdw;" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"Done.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"CREATE SERVER northwind FOREIGN DATA WRAPPER file_fdw;" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"In the tutorial, paths are set to `D:\\northwind\\` that need changing, eg to `/home/agens/AgensGraph/shareddata` (the path the data was mounted to in the setup). Note that the path is the path *inside the `agens` container*. that For convenience, we also mount that volume across to the notebook `/home/jovyan/agens` directory so that we can pass files from the notebook container to the `agens` container." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#The path is path we mounted the data onto in the agensgraph container\n", | |
"PATH = '/home/agens/AgensGraph/shareddata'\n", | |
"\n", | |
"setup='''\n", | |
"-- Go defensive\n", | |
"DROP FOREIGN TABLE IF EXISTS categories;\n", | |
"DROP FOREIGN TABLE IF EXISTS customers;\n", | |
"DROP FOREIGN TABLE IF EXISTS employees;\n", | |
"DROP FOREIGN TABLE IF EXISTS employee_territories;\n", | |
"DROP FOREIGN TABLE IF EXISTS orders_details;\n", | |
"DROP FOREIGN TABLE IF EXISTS orders;\n", | |
"DROP FOREIGN TABLE IF EXISTS products;\n", | |
"DROP FOREIGN TABLE IF EXISTS regions;\n", | |
"DROP FOREIGN TABLE IF EXISTS shippers;\n", | |
"DROP FOREIGN TABLE IF EXISTS suppliers;\n", | |
"DROP FOREIGN TABLE IF EXISTS territories;\n", | |
"\n", | |
"CREATE FOREIGN TABLE categories (\n", | |
"CategoryID int,\n", | |
"CategoryName varchar(15),\n", | |
"Description text,\n", | |
"Picture bytea\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/categories.csv', delimiter ',', quote '\"', null '');\n", | |
"\n", | |
"CREATE FOREIGN TABLE customers (\n", | |
"CustomerID char(5),\n", | |
"CompanyName varchar(40),\n", | |
"ContactName varchar(30),\n", | |
"ContactTitle varchar(30),\n", | |
"Address varchar(60),\n", | |
"City varchar(15),\n", | |
"Region varchar(15),\n", | |
"PostalCode varchar(10),\n", | |
"Country varchar(15),\n", | |
"Phone varchar(24),\n", | |
"Fax varchar(24)\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/customers.csv', delimiter ',', quote '\"', null '');\n", | |
"\n", | |
"CREATE FOREIGN TABLE employees (\n", | |
"EmployeeID int,\n", | |
"LastName varchar(20),\n", | |
"FirstName varchar(10),\n", | |
"Title varchar(30),\n", | |
"TitleOfCourtesy varchar(25),\n", | |
"BirthDate date,\n", | |
"HireDate date,\n", | |
"Address varchar(60),\n", | |
"City varchar(15),\n", | |
"Region varchar(15),\n", | |
"PostalCode varchar(10),\n", | |
"Country varchar(15),\n", | |
"HomePhone varchar(24),\n", | |
"Extension varchar(4),\n", | |
"Photo bytea,\n", | |
"Notes text,\n", | |
"ReportTo int,\n", | |
"PhotoPath varchar(255)\n", | |
") \n", | |
"SERVER northwind \n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/employees.csv', delimiter ',', quote '\"', null '');\n", | |
"\n", | |
"CREATE FOREIGN TABLE employee_territories (\n", | |
"EmployeeID int,\n", | |
"TerritoryID varchar(20)\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/employee_territories.csv', delimiter ',', quote '\"', null ''); \n", | |
"\n", | |
"CREATE FOREIGN TABLE orders_details (\n", | |
"orderID int,\n", | |
"ProductID int,\n", | |
"UnitPrice money,\n", | |
"Quantity smallint,\n", | |
"Discount real\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/orders_details.csv', delimiter ',', quote '\"', null ''); \n", | |
"\n", | |
"CREATE FOREIGN TABLE orders (\n", | |
"orderID int,\n", | |
"CustomerID char(5),\n", | |
"EmployeeID int,\n", | |
"orderDate date,\n", | |
"RequiredDate date,\n", | |
"ShippedDate date,\n", | |
"ShipVia int,\n", | |
"Freight money,\n", | |
"ShipName varchar(40),\n", | |
"ShipAddress varchar(60),\n", | |
"ShipCity varchar(15),\n", | |
"ShipRegion varchar(15), \n", | |
"ShipPostalCode varchar(10), \n", | |
"ShipCountry varchar(15) \n", | |
") \n", | |
"SERVER northwind \n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/orders.csv', delimiter ',', quote '\"', null ''); \n", | |
"\n", | |
"CREATE FOREIGN TABLE products (\n", | |
"ProductID int, \n", | |
"ProductName varchar(40),\n", | |
"SupplierID int, \n", | |
"CategoryID int, \n", | |
"QuantityPerUnit varchar(20),\n", | |
"UnitPrice money, \n", | |
"UnitsInStock smallint, \n", | |
"UnitsOnorder smallint, \n", | |
"ReorderLevel smallint, \n", | |
"Discontinued bit \n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/products.csv', delimiter ',', quote '\"', null '');\n", | |
"\n", | |
"CREATE FOREIGN TABLE regions (\n", | |
"RegionID int,\n", | |
"RegionDescription char(50)\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/regions.csv', delimiter ',', quote '\"', null ''); \n", | |
"\n", | |
"CREATE FOREIGN TABLE shippers (\n", | |
"ShipperID int,\n", | |
"CompanyName varchar(40),\n", | |
"Phone varchar(24)\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/shippers.csv', delimiter ',', quote '\"', null ''); \n", | |
"\n", | |
"CREATE FOREIGN TABLE suppliers (\n", | |
"SupplierID int,\n", | |
"CompanyName varchar(40),\n", | |
"ContactName varchar(30),\n", | |
"ContactTitle varchar(30),\n", | |
"Address varchar(60),\n", | |
"City varchar(15),\n", | |
"Region varchar(15),\n", | |
"PostalCode varchar(10),\n", | |
"Country varchar(15),\n", | |
"Phone varchar(24),\n", | |
"Fax varchar(24),\n", | |
"HomePage text\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/suppliers.csv', delimiter ',', quote '\"', null '');\n", | |
"\n", | |
"CREATE FOREIGN TABLE territories (\n", | |
"TerritoryID varchar(20),\n", | |
"TerritoryDescription char(50),\n", | |
"RegionID int\n", | |
") \n", | |
"SERVER northwind\n", | |
"OPTIONS (FORMAT 'csv', HEADER 'true', FILENAME '{path}/territories.csv', delimiter ',', quote '\"', null '');\n", | |
"'''.format(path=PATH)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%sql $setup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 20, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"-- Go defensive\n", | |
"DROP GRAPH IF EXISTS northwind_graph CASCADE;\n", | |
"\n", | |
"CREATE GRAPH northwind_graph;\n", | |
"SET graph_path = northwind_graph;" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Loading the data in requires the data to be mounted in the database container (unless we can help `psycopg2` load files stored in the notebook container into the `agensgraph` container?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * postgresql://agens:***@agensgraph_container/agens\n", | |
" postgresql://agens:***@agensgraph_container/postgres\n", | |
" postgresql://postgres:***@postgres_container/postgres\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n", | |
"Done.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%sql\n", | |
"LOAD FROM categories AS source CREATE (n:category=to_jsonb(source));\n", | |
"LOAD FROM customers AS source CREATE (n:customer=to_jsonb(source));\n", | |
"LOAD FROM employees AS source CREATE (n:employee=to_jsonb(source));\n", | |
"create vlabel if not exists \"order\";\n", | |
"LOAD FROM orders AS source CREATE (n:\"order\"=to_jsonb(source));\n", | |
"LOAD FROM products AS source CREATE (n:product=to_jsonb(source));\n", | |
"LOAD FROM regions AS source CREATE (n:region=to_jsonb(source));\n", | |
"LOAD FROM shippers AS source CREATE (n:shipper=to_jsonb(source));\n", | |
"LOAD FROM suppliers AS source CREATE (n:supplier=to_jsonb(source));\n", | |
"LOAD FROM territories AS source CREATE (n:territory=to_jsonb(source));" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Based on: https://github.com/khezen/compose-postgres | |
version: '3.5' | |
services: | |
agensgraph: | |
#https://github.com/bitnine-oss/agensgraph-docker | |
container_name: agensgraph_agens_container | |
image: bitnine/agensgraph | |
#Keep alive: https://stackoverflow.com/a/45450456/454773 | |
command: tail -F /dev/null | |
#credentials: user: agens, pwd: agens | |
networks: | |
- agensgraph | |
volumes: | |
- agensgraph:/home/agens/AgensGraph/shareddata | |
#ports: | |
# - "5432:5432" | |
restart: unless-stopped | |
postgres: | |
container_name: agensgraph_postgres_container | |
image: postgres | |
environment: | |
POSTGRES_USER: ${POSTGRES_USER:-postgres} | |
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme} | |
PGDATA: /data/postgres | |
volumes: | |
- postgres:/data/postgres | |
#ports: | |
# - "5432:5432" | |
networks: | |
- agensgraph | |
restart: unless-stopped | |
#pgadmin: | |
# container_name: agensgraph_pgadmin_container | |
# image: dpage/pgadmin4 | |
# environment: | |
# PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} | |
# PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} | |
# volumes: | |
# - pgadmin:/root/.pgadmin | |
# ports: | |
# - "${PGADMIN_PORT:-5055}:80" | |
# networks: | |
# - agensgraph | |
# restart: unless-stopped | |
jupyter: | |
container_name: agensgraph_jupyter_notebook_container | |
#image: jupyter/minimal-notebook | |
build: | |
context: . | |
dockerfile: Dockerfile-jupyter | |
environment: | |
JUPYTER_TOKEN: "$JUPYTER_TOKEN" | |
ports: | |
- "80:8888" | |
volumes: | |
- agensgraph:/home/jovyan/agensgraph | |
#A file needs to be mounted against a file, not a directory | |
- ./DatabaseConnections.ipynb:/home/jovyan/work/DatabaseConnections.ipynb | |
networks: | |
- agensgraph | |
restart: unless-stopped | |
networks: | |
agensgraph: | |
driver: bridge | |
volumes: | |
agensgraph: | |
#pgadmin: | |
postgres: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM jupyter/minimal-notebook | |
#Install SQL magic support | |
RUN pip install --no-cache pandas | |
RUN pip install --no-cache psycopg2-binary | |
RUN pip install --no-cache git+https://github.com/catherinedevlin/ipython-sql | |
RUN pip install --no-cache git+https://github.com/pivotal-legacy/sql_magic | |
RUN pip install --no-cache git+https://github.com/andialbrecht/sqlparse | |
#ADD will automatically unzip the contents of gzipped file into the destination directory | |
#But not .zip file? | |
COPY import-northwind-dataset.zip ./ | |
RUN unzip import-northwind-dataset.zip -d /home/jovyan/agensgraph | |
RUN rm ./import-northwind-dataset.zip | |
#Run the container | |
#docker run --rm -d -p 8899:8888 --name pgnotebook psychemedia/pgnotebook | |
##Or: docker run --rm -d --expose 8888 --name pgnotebook psychemedia/pgnotebook | |
#Or with a custom token: | |
#docker run --rm -d -p 8899:8888 --name pgnotebook -e JUPYTER_TOKEN='letmeout' psychemedia/pgnotebook | |
#Tidy up after running | |
#docker kill pgnotebook | |
#docker rm pgnotebook | |
#Push container to Docker hub (must be logged in) | |
#docker push psychemedia/pgnotebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Optionally: | |
#export JUPYTER_TOKEN=myOwnPA5%w0rD | |
GIST=8fa117e34c62b7f80b6c595b8ba4f488 | |
git clone https://gist.github.com/$GIST.git | |
cd $GIST | |
docker-compose up -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment