Permalink
Browse files

Add Makefile and schema.sql to build the DB

  • Loading branch information...
adomokos committed Nov 28, 2017
1 parent 873bacf commit ff40249ac7bc767e9f57b52daccf690cbf3bae1a
Showing with 66 additions and 0 deletions.
  1. +32 −0 Makefile
  2. +34 −0 resources/schema.sql
View
@@ -0,0 +1,32 @@
DBUSER=hashmir_user
DBPASSWD=shei7AnganeihaeF
DBNAME=hashmir_test
HOST=localhost
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.DEFAULT_GOAL := help
create-db-user: ## Creates a DB user with the root MySQL user
mysql -u root --host $(HOST) -e "CREATE USER '$(DBUSER)'@'$(HOST)' IDENTIFIED BY '$(DBPASSWD)';" > /dev/null 2>&1
mysql -u root --host $(HOST) -e "GRANT ALL PRIVILEGES ON `$(DBNAME)`.* TO '$(DBUSER)'@'$(HOST)';" > /dev/null 2>&1
build-db: ## Builds the DB
@echo "Dropping and rebuilding database $(DBNAME)"
@mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) -e "DROP DATABASE IF EXISTS $(DBNAME);" > /dev/null 2>&1
@mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) -e "CREATE DATABASE $(DBNAME);" > /dev/null 2>&1
@mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) $(DBNAME) < resources/schema.sql > /dev/null 2>&1
dbconnect: ## Connect to the DB with mysql console
mysql --user=$(DBUSER) --password='$(DBPASSWD)' --host=$(HOST) $(DBNAME)
build: ## Builds the project with stack
@stack build && stack install
run: build-db ## Runs the app
time ~/.local/bin/hashmir-exe
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
View
@@ -0,0 +1,34 @@
DROP TABLE IF EXISTS `clients`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `clients` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`subdomain` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`trial` tinyint(1) NOT NULL DEFAULT 0,
`api_key` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `index_clients_on_subdomain` (`subdomain`),
KEY `index_clients_on_api_key` (`api_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`client_id` int(11) NOT NULL,
`login` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_in_count` int(11) NOT NULL DEFAULT 0,
`firstname` varchar(255) DEFAULT NULL,
`lastname` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `index_users_on_email` (`email`),
CONSTRAINT `client_id` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

0 comments on commit ff40249

Please sign in to comment.