Updating repo structure
This commit is contained in:
parent
46d5f8a64f
commit
7b13322ba8
|
@ -0,0 +1 @@
|
|||
.DS_Store
|
Binary file not shown.
|
@ -1,94 +0,0 @@
|
|||
from datetime import timedelta, datetime
|
||||
from random import randint
|
||||
from random import choice as rc
|
||||
import sqlite3
|
||||
|
||||
|
||||
# This function will return a random datetime between two datetime objects.
|
||||
def random_date(start, end):
|
||||
return start + timedelta(seconds=randint(0, int((end - start).total_seconds())))
|
||||
|
||||
# Connect to the DB
|
||||
conn = sqlite3.connect('Northwind.sqlite')
|
||||
c = conn.cursor()
|
||||
|
||||
# ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode
|
||||
c.execute("select distinct ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry from [Order]")
|
||||
locations = [(row[0], row[1], row[2], row[3], row[4], row[5]) for row in c.fetchall()]
|
||||
|
||||
# Customer.Id
|
||||
c.execute("select distinct id from [Employee]")
|
||||
employees = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Shipper.Id
|
||||
c.execute("select distinct id from [Shipper]")
|
||||
shippers = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Customer.Id
|
||||
c.execute("select distinct id from [Customer]")
|
||||
customers = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Create a bunch of new orders
|
||||
for i in range(randint(15000,16000)):
|
||||
sql = 'INSERT INTO [Order] (CustomerId, EmployeeId, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
location = rc(locations)
|
||||
order_date = random_date(datetime.strptime('2012-07-10', '%Y-%m-%d'), datetime.today())
|
||||
required_date = random_date(order_date, order_date+timedelta(days=randint(14,60)))
|
||||
shipped_date = random_date(order_date, order_date+timedelta(days=randint(1,30)))
|
||||
params = (
|
||||
rc(customers), # CustomerId
|
||||
rc(employees), # EmployeeId
|
||||
order_date, # OrderDate
|
||||
required_date, # RequiredDate
|
||||
shipped_date, # ShippedDate
|
||||
rc(shippers), # ShipVia
|
||||
0.00, # Freight
|
||||
location[0], # ShipName
|
||||
location[1], # ShipAddress
|
||||
location[2], # ShipCity
|
||||
location[3], # ShipRegion
|
||||
location[4], # ShipPostalCode
|
||||
location[5], # ShipCountry
|
||||
)
|
||||
c.execute(sql,params)
|
||||
|
||||
|
||||
# Product.Id
|
||||
c.execute("select distinct id, UnitPrice from [Product]")
|
||||
products = [(row[0], row[1]) for row in c.fetchall()]
|
||||
|
||||
# Order.Id
|
||||
c.execute("select distinct id from [Order] where Freight = 0.00")
|
||||
orders = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Fill the order with items
|
||||
for order in orders:
|
||||
used = []
|
||||
for x in range(randint(1,len(products))):
|
||||
sql = 'INSERT INTO [OrderDetail] (Id, OrderId, ProductId, UnitPrice, Quantity, Discount) VALUES (?, ?, ?, ?, ?, ?)'
|
||||
control = 1
|
||||
while control:
|
||||
product = rc(products)
|
||||
if product not in used:
|
||||
used.append(product)
|
||||
control = 0
|
||||
params = (
|
||||
"%s/%s" % (order, product[0]),
|
||||
order, # OrderId
|
||||
product[0], # ProductId
|
||||
product[1], # UnitPrice
|
||||
randint(1,50), # Quantity
|
||||
0, # Discount
|
||||
)
|
||||
c.execute(sql,params)
|
||||
|
||||
# Cleanup
|
||||
# c.execute('update [Order] set OrderDate = date(OrderDate), RequiredDate = date(RequiredDate), ShippedDate = date(ShippedDate)')
|
||||
c.execute("select sum(Quantity)*0.25+10, OrderId from [OrderDetail] group by OrderId")
|
||||
orders = [(row[0],row[1]) for row in c.fetchall()]
|
||||
for order in orders:
|
||||
c.execute("update [Order] set Freight=? where Id=?", (order[0], order[1]))
|
||||
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
Binary file not shown.
36
README.md
36
README.md
|
@ -1,9 +1,39 @@
|
|||
# northwind-SQLite3
|
||||
# Northwind-SQLite3
|
||||
|
||||
This is a version of the Microsoft Access 2000 Northwind sample database, re-engineered for SQLite3.
|
||||
|
||||
The Northwind sample database was provided with Microsoft Access as a tutorial schema for managing small business customers, orders, inventory, purchasing, suppliers, shipping, and employees. Northwind is an excellent tutorial schema for a small-business ERP, with customers, orders, inventory, purchasing, suppliers, shipping, employees, and single-entry accounting.
|
||||
|
||||
All the TABLES and VIEWS from the MSSQL-2000 version have been converted to Sqlite3 and included here. Also included are two versions prepopulated with data - a small verison and a large version. Should you decide to, you can use the included python script to pump the database full of more data.
|
||||
All the TABLES and VIEWS from the MSSQL-2000 version have been converted to Sqlite3 and included here. Included is a single version prepopulated with data. Should you decide to, you can use the included python script to pump the database full of more data.
|
||||
|
||||
![alt tag](https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master/Northwind_ERD.png)
|
||||
[Download here](https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master/dist/northwind.db)
|
||||
|
||||
# Structure
|
||||
|
||||
![alt tag](https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/master/images/Northwind_ERD.png)
|
||||
|
||||
# Build Instructions
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- You are running in a unix-like environment (Linux, MacOS)
|
||||
- Python 3.6 or higher (`python3 --version`)
|
||||
- SQLite3 installed `sqlite3 -help`
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
make build # Creates database at ./dist/northwind.db
|
||||
```
|
||||
|
||||
## Populate with more data
|
||||
|
||||
```bash
|
||||
make populate
|
||||
```
|
||||
|
||||
## Print report of row counts
|
||||
|
||||
```bash
|
||||
make report
|
||||
```
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
|
@ -0,0 +1,23 @@
|
|||
.PHONY: clean build run
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
|
||||
bootstrap:
|
||||
brew install sqlite
|
||||
brew install graphviz
|
||||
|
||||
clean:
|
||||
rm -rf ./dist
|
||||
mkdir ./dist
|
||||
|
||||
build: clean
|
||||
sqlite3 dist/northwind.db < src/create.sql > /dev/null
|
||||
sqlite3 dist/northwind.db < src/update.sql > /dev/null
|
||||
sqlite3 dist/northwind.db < src/report.sql
|
||||
|
||||
populate:
|
||||
python3 ./src/populate.py
|
||||
sqlite3 dist/northwind.db < src/report.sql
|
||||
|
||||
report:
|
||||
sqlite3 dist/northwind.db < src/report.sql
|
|
@ -1,6 +1,3 @@
|
|||
-- Valon Hoti @ 2010-07-04 [YYYY-MM-DD]
|
||||
-- Prishtine,10000
|
||||
-- KOSOVE
|
||||
-- DATABASE : Northwind
|
||||
-- ORIGIN : MS SQL
|
||||
-- SOURCE : SQLITE 3
|
||||
|
@ -8,8 +5,6 @@
|
|||
-- Converted TABLES and VIEWS from MS SQL 2000 to Sqlite 3
|
||||
--
|
||||
|
||||
-- Modified by Len Boyette @ 2013-02-08
|
||||
-- Added foreign keys
|
||||
PRAGMA foreign_keys=off;
|
||||
|
||||
-- Categories
|
|
@ -0,0 +1,101 @@
|
|||
from datetime import timedelta, datetime
|
||||
from random import randint
|
||||
from random import choice as rc
|
||||
import sqlite3
|
||||
|
||||
|
||||
# This function will return a random datetime between two datetime objects.
|
||||
def random_date(start, end):
|
||||
return start + timedelta(seconds=randint(0, int((end - start).total_seconds())))
|
||||
|
||||
|
||||
# Connect to the DB
|
||||
conn = sqlite3.connect("./dist/northwind.db")
|
||||
c = conn.cursor()
|
||||
|
||||
# ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode
|
||||
c.execute(
|
||||
"select distinct ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry from [Orders]"
|
||||
)
|
||||
locations = [(row[0], row[1], row[2], row[3], row[4], row[5]) for row in c.fetchall()]
|
||||
|
||||
# Customer.Id
|
||||
c.execute("select distinct EmployeeId from [Employees]")
|
||||
employees = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Shipper.Id
|
||||
c.execute("select distinct ShipperId from [Shippers]")
|
||||
shippers = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Customer.Id
|
||||
c.execute("select distinct CustomerId from [Customers]")
|
||||
customers = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Create a bunch of new orders
|
||||
for i in range(randint(15000, 16000)):
|
||||
sql = "INSERT INTO [Orders] (CustomerId, EmployeeId, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
location = rc(locations)
|
||||
order_date = random_date(
|
||||
datetime.strptime("2012-07-10", "%Y-%m-%d"), datetime.today()
|
||||
)
|
||||
required_date = random_date(
|
||||
order_date, order_date + timedelta(days=randint(14, 60))
|
||||
)
|
||||
shipped_date = random_date(order_date, order_date + timedelta(days=randint(1, 30)))
|
||||
params = (
|
||||
rc(customers), # CustomerId
|
||||
rc(employees), # EmployeeId
|
||||
order_date, # OrderDate
|
||||
required_date, # RequiredDate
|
||||
shipped_date, # ShippedDate
|
||||
rc(shippers), # ShipVia
|
||||
0.00, # Freight
|
||||
location[0], # ShipName
|
||||
location[1], # ShipAddress
|
||||
location[2], # ShipCity
|
||||
location[3], # ShipRegion
|
||||
location[4], # ShipPostalCode
|
||||
location[5], # ShipCountry
|
||||
)
|
||||
c.execute(sql, params)
|
||||
|
||||
|
||||
# Product.Id
|
||||
c.execute("select distinct ProductId, UnitPrice from [Products]")
|
||||
products = [(row[0], row[1]) for row in c.fetchall()]
|
||||
|
||||
# Order.Id
|
||||
c.execute("select distinct OrderId from [Orders] where Freight = 0.00")
|
||||
orders = [row[0] for row in c.fetchall()]
|
||||
|
||||
# Fill the order with items
|
||||
for order in orders:
|
||||
used = []
|
||||
for x in range(randint(1, len(products))):
|
||||
sql = "INSERT INTO [Order Details] (OrderId, ProductId, UnitPrice, Quantity, Discount) VALUES (?, ?, ?, ?, ?)"
|
||||
control = 1
|
||||
while control:
|
||||
product = rc(products)
|
||||
if product not in used:
|
||||
used.append(product)
|
||||
control = 0
|
||||
params = (
|
||||
# "%s/%s" % (order, product[0]),
|
||||
order, # OrderId
|
||||
product[0], # ProductId
|
||||
product[1], # UnitPrice
|
||||
randint(1, 50), # Quantity
|
||||
0, # Discount
|
||||
)
|
||||
c.execute(sql, params)
|
||||
|
||||
# Cleanup
|
||||
# c.execute('update [Order] set OrderDate = date(OrderDate), RequiredDate = date(RequiredDate), ShippedDate = date(ShippedDate)')
|
||||
c.execute("select sum(Quantity)*0.25+10, OrderId from [Order Details] group by OrderId")
|
||||
orders = [(row[0], row[1]) for row in c.fetchall()]
|
||||
for order in orders:
|
||||
c.execute("update [Orders] set Freight=? where OrderId=?", (order[0], order[1]))
|
||||
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
|
@ -0,0 +1,13 @@
|
|||
select "Categories", count(*) from [Categories];
|
||||
select "CustomerCustomerDemo", count(*) from [CustomerCustomerDemo];
|
||||
select "CustomerDemographics", count(*) from [CustomerDemographics];
|
||||
select "Customers", count(*) from [Customers];
|
||||
select "EmployeeTerritories", count(*) from [EmployeeTerritories];
|
||||
select "Employees", count(*) from [Employees];
|
||||
select "Details", count(*) from [Order Details];
|
||||
select "Orders", count(*) from [Orders];
|
||||
select "Products", count(*) from [Products];
|
||||
select "Regions", count(*) from [Regions];
|
||||
select "Shippers", count(*) from [Shippers];
|
||||
select "Suppliers", count(*) from [Suppliers];
|
||||
select "Territories", count(*) from [Territories];
|
|
@ -22,8 +22,8 @@ update [Customers] set Region='Scandinavia' where Country='Finland';
|
|||
|
||||
update [Employees] set Region='British Isles' where Country='UK';
|
||||
update [Employees] set Region='North America' where Country='USA';
|
||||
update [Employees] set BirthDate = date(BirthDate,'+16 year');
|
||||
update [Employees] set HireDate = date(HireDate,'+16 year');
|
||||
update [Employees] set BirthDate = date(BirthDate,'+20 year');
|
||||
update [Employees] set HireDate = date(HireDate,'+20 year');
|
||||
|
||||
update [Orders] set ShipRegion='British Isles' where ShipCountry='UK';
|
||||
update [Orders] set ShipRegion='British Isles' where ShipCountry='Ireland';
|
||||
|
@ -47,9 +47,9 @@ update [Orders] set ShipRegion='Western Europe' where ShipCountry='Austria';
|
|||
update [Orders] set ShipRegion='Scandinavia' where ShipCountry='Norway';
|
||||
update [Orders] set ShipRegion='Scandinavia' where ShipCountry='Finland';
|
||||
|
||||
update [Orders] set OrderDate = date(OrderDate,'+16 year');
|
||||
update [Orders] set RequiredDate = date(RequiredDate,'+16 year');
|
||||
update [Orders] set ShippedDate = date(ShippedDate,'+16 year');
|
||||
update [Orders] set OrderDate = date(OrderDate,'+20 year');
|
||||
update [Orders] set RequiredDate = date(RequiredDate,'+20 year');
|
||||
update [Orders] set ShippedDate = date(ShippedDate,'+20 year');
|
||||
|
||||
update [Suppliers] set Region='British Isles' where Country='UK';
|
||||
update [Suppliers] set Region='British Isles' where Country='Ireland';
|
Loading…
Reference in New Issue