-- Database-CopyMasterListsToShell.sql
/*
2014-10-12 Tom Holden ve3meo
2014-10-14 rev to copy user settings for RM File Options

Copies from a developed RootsMagic database to a new empty database
of the same version:
- customized standard fact types
- custom fact types
- master sources
- media items tagged to sources and places
- addresses for repositories and contacts
- custom source templates
- user defined places
- webtags for sources and places
- user settings for File Options

Usage: requires SQLite Expert Personal with unifuzz.dll extension loaded 
       OR equivalent SQLite manager that supports runtime variables and fake
       RMNOCASE  
  1. Create a new empty database using RootsMagic; note the full path; close the database.
  2. Open the developed database as Main in the SQLite manager;
  3. Load and execute the script;
  4. Enter the full path to and name of the shell database at the prompt;  
  5. On finishing the script, open the shell database with RootsMagic; run Database Tools > Rebuild Indexes. 
  6. Close and reopen the database with RM to reset the start person and last person config settings. 


*/

--------------START OF SCRIPT-------------------
ATTACH $ShellFileFullPathName AS shell  -- enter the full path to and name of the shell database at runtime
;

BEGIN TRANSACTION
;
-- Delete all Fact Types from shell 
DELETE FROM shell.FactTypeTable
;
-- Insert standard and custom Fact Types from main into shell
INSERT INTO shell.FactTypeTable
SELECT * FROM main.FactTypeTable
;
-- Delete all roles from RoleTable
DELETE FROM shell.RoleTable
;
-- Insert standard and custom Roles from main into shell
INSERT INTO shell.RoleTable
SELECT * FROM main.RoleTable
;
-- Insert master sources from main into shell
INSERT INTO shell.SourceTable
SELECT * FROM main.SourceTable
;
-- Insert custom Source Templates from main into shell
INSERT INTO shell.SourceTemplateTable
SELECT * FROM main.SourceTemplateTable
WHERE TemplateID >9999
;
-- Insert address links for sources et al from main into shell
INSERT INTO shell.AddressLinkTable
SELECT * FROM main.AddressLinkTable
;
-- Insert addresses from main into shell
INSERT INTO shell.AddressTable
SELECT * FROM main.AddressTable
;
-- Insert user-defined places from main into shell
INSERT INTO shell.PlaceTable
SELECT * FROM main.PlaceTable
WHERE PlaceType <> 1
;
-- Insert media links for sources and places from main into shell
INSERT INTO shell.MediaLinkTable
SELECT * FROM main.MediaLinkTable
WHERE OwnerType IN (3,5)
;
-- Insert multimedia for sources and places from main into shell
INSERT INTO shell.MultiMediaTable
SELECT * FROM main.MultiMediaTable
WHERE MediaID IN (SELECT DISTINCT MediaID FROM shell.MediaLinkTable)
;
-- Insert Web Tags for sources and places from main into shell
INSERT INTO shell.URLTable
SELECT * FROM main.URLTable
WHERE OwnerType IN (3,5)
;
-- Copy File Options from main into shell 2014-10-14
DELETE FROM shell.ConfigTable
;
INSERT INTO shell.ConfigTable
SELECT * FROM main.ConfigTable
;

COMMIT TRANSACTION
;
DETACH shell
;
-- Throw up a little message
SELECT '----------- Script completed -----------' AS [Status]
;
--------------END of SCRIPT----------------
 

