Created
November 23, 2019 18:37
-
-
Save sitedyno/7dbeeddaaa8ddb2568aa64cfb08a6fe6 to your computer and use it in GitHub Desktop.
make can be nifty at times...
This file contains hidden or 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
# prefix all files with current datetime | |
date=`date +%Y-%m-%d_%H:%m:%S` | |
db="tmp/$(date).db" | |
define MigrateBlocks | |
/*create new table*/ | |
CREATE TABLE `new_blocks` ( | |
`id` INTEGER NULL PRIMARY KEY AUTOINCREMENT | |
, `region_id` INTEGER NULL | |
, `title` VARCHAR(100) NULL | |
, `alias` VARCHAR(100) NULL | |
, `body` TEXT NULL | |
, `show_title` BOOLEAN NOT NULL DEFAULT 1 | |
, `class` VARCHAR(255) NULL | |
, `status` INTEGER NULL | |
, `weight` INTEGER NULL | |
, `element` VARCHAR(255) NULL | |
, `visibility_roles` TEXT NULL | |
, `visibility_paths` TEXT NULL | |
, `visibility_php` TEXT NULL | |
, `params` TEXT NULL | |
, `publish_start` DATETIME NULL | |
, `publish_end` DATETIME NULL | |
, `updated` DATETIME NULL | |
, `updated_by` INTEGER NULL | |
, `created` DATETIME NULL | |
, `created_by` INTEGER NULL | |
); | |
/*insert old data into new table*/ | |
INSERT INTO new_blocks SELECT | |
id,region_id,title,alias,body,show_title,class,status,weight,element,visibility_roles, | |
visibility_paths,visibility_php,params,NULL,NULL,updated,1,created,1 | |
FROM blocks WHERE id in (15,14,13,12,11,10); | |
/*drop the old table*/ | |
DROP TABLE blocks; | |
/*rename the new table*/ | |
ALTER TABLE new_blocks RENAME TO blocks; | |
endef | |
.PHONY: help clean build | |
help: | |
@echo "make clean" | |
@echo "Removes all temporary & build artifacts" | |
@echo "" | |
@echo "make build" | |
@echo "Builds sql file to be used for import to new database" | |
clean: | |
rm -rf tmp/* | |
rm -rf build/* | |
export MigrateBlocks | |
build: | |
# create a disposable copy of original db | |
cp 2013.sacredheartvidalia.org.db $(db) | |
sqlite3 $(db) "$$MigrateBlocks" | |
sqlite3 $(db) 'select id,title,weight from blocks;' | |
sqlite3 $(db) '.dump blocks' > tmp/dump.sql | |
sqlite3 $(db) '.schema blocks' > tmp/schema.sql | |
grep -vx -f tmp/schema.sql tmp/dump.sql > tmp/migration.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment