Database Schema Deployment. Lukas Smith - lukas@liip.ch CodeWorks 2009 - PHP on the ROAD



Similar documents
php tek 2006 in Orlando Florida Lukas Kahwe Smith

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

Oracle 10g PL/SQL Training

Linas Virbalas Continuent, Inc.

Database as a Service (DaaS) Version 1.02

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Oracle SQL. Course Summary. Duration. Objectives

How to Improve Database Connectivity With the Data Tools Platform. John Graham (Sybase Data Tooling) Brian Payton (IBM Information Management)

Database Migration from MySQL to RDM Server

How To Create A Table In Sql (Ahem)

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

OBJECTS AND DATABASES. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 21

PAINLESS MULTI-DBMS STRATEGY For Magic Developers

Toad Data Modeler - Features Matrix

A Comparative Study of Database Design Tools

Oracle Database 11g SQL

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Comparing SQL and NOSQL databases

Introduction to Triggers using SQL

Oracle Database 12c: Introduction to SQL Ed 1.1

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Netezza Workbench Documentation

Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen, M.Sc.

Oracle Database: SQL and PL/SQL Fundamentals NEW

Auditing Data Access Without Bringing Your Database To Its Knees

Database Programming with PL/SQL: Learning Objectives

Application Development With Data Studio

Oracle Database: Introduction to SQL

SQL SERVER DEVELOPER Available Features and Tools New Capabilities SQL Services Product Licensing Product Editions Will teach in class room

Oracle Database: SQL and PL/SQL Fundamentals

Embarcadero DB Change Manager 6.0 and DB Change Manager XE2

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

NEMUG Feb Create Your Own Web Data Mart with MySQL

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

ATTACHMENT 6 SQL Server 2012 Programming Standards

Toad for Data Analysts, Tips n Tricks

SQL Server Training Course Content

Tracking Database Schema Changes. Guidelines on database versioning using Devart tools


In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

What's New with SQL Developer Data Modeler. Heli Helskyaho HrOUG 2015

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Introduction to Database. Systems HANS- PETTER HALVORSEN,

Oracle(PL/SQL) Training

Enabling development teams to move fast. PostgreSQL at Zalando

Guide to the MySQL Workbench Migration Wizard: From Microsoft SQL Server to MySQL

Adam Rauch Partner, LabKey Software Extending LabKey Server Part 1: Retrieving and Presenting Data

SQL. Short introduction

Short notes on webpage programming languages

1. INTRODUCTION TO RDBMS

SQL Server 2008 Core Skills. Gary Young 2011

Rapid SQL 7.6 Evaluation Guide. Published: January 12, 2009

Oracle Database 10g: Introduction to SQL

DBMS / Business Intelligence, SQL Server

Relational Databases for the Business Analyst

Embarcadero Rapid SQL Developer 2.0 User Guide

edoc Document Generation Suite

INTRODUCTION TO DATABASE SYSTEMS

CS 564: DATABASE MANAGEMENT SYSTEMS

Case Studies. Database

Shadowbase Data Replication Solutions. William Holenstein Senior Manager of Product Delivery Shadowbase Products Group

SQL, PL/SQL FALL Semester 2013

4. The Third Stage In Designing A Database Is When We Analyze Our Tables More Closely And Create A Between Tables

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Cross Platform Software Release Capabilities

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

Oracle Database 10g Express

Rapid SQL XE Product Reviewer Guide

1 Structured Query Language: Again. 2 Joining Tables

Managing Third Party Databases and Building Your Data Warehouse

Database migration. from Sybase ASE to PostgreSQL. Achim Eisele and Jens Wilke. 1&1 Internet AG

<Insert Picture Here> Introducing Data Modeling and Design with Oracle SQL Developer Data Modeler

Database Extension 1.5 ez Publish Extension Manual

Real-time Data Replication

Informatica Data Replication FAQs

<Insert Picture Here> Application Change Management and Data Masking

Enabling Continuous Delivery with Database Practices

EMBL-EBI. Database Replication - Distribution

Oracle Database Development Standards For DNR Staff and Contractors. Table of Contents

Databases What the Specification Says

PG DAC. Syllabus. Content. Eligibility Criteria

Lab 2: PostgreSQL Tutorial II: Command Line

MySQL Command Syntax

SQL Anywhere 12 New Features Summary

Oracle to SQL Server 2005 Migration

2015, André Melancia (Andy.PT) 1

Instant SQL Programming

Introduction to Databases

IBM Campaign and IBM Silverpop Engage Version 1 Release 2 August 31, Integration Guide IBM

MySQL Administration and Management Essentials

Introduction. Introduction: Database management system. Introduction: DBS concepts & architecture. Introduction: DBS versus File system

Consolidate by Migrating Your Databases to Oracle Database 11g. Fred Louis Enterprise Architect

Database programming made easier Master thesis of Roland Balk

Oracle Insurance Policy Administration. Version

Transcription:

Database Schema Deployment Lukas Smith - lukas@liip.ch CodeWorks 2009 - PHP on the ROAD

Agenda The Challenge ER Tools Diff Tools Data synchronisation Tools Logging Changes XML Formats SCM Tools Manual Scripting

Terminology DDL - Data Definition Language: CREATE, ALTER, DROP DML - Data Manipulation Language: SELECT, INSERT, UPDATE, DELETE

The Challenge Getting the DDL and DML to update/downgrade SQL diff tools can generate DDL Data synchronisation very tricky, especially of DDL and DML need to be mixed in a particular order Do not deal well with object dependencies like Foreign Keys, Views, Stored Routines Sloppy code can break even if theoretically the database schema is the same

Example Version 1.0.0: User table with a single phone number Version 1.1.0: Allow infinite phone numbers per user by adding a phone numbers table Add new table: CREATE TABLE phone_nums (user_id INT REFERENCES user, phone_num CHAR(20)) Move all data: INSERT INTO phone_nums SELECT user_id, phone_num FROM users Drop the old column: ALTER TABLE users DROP COLUMN phone_num

ER Tools ER Modeling tools to visually design schema Usually support schema reverse engineering and synchronizing to a file or live database MySQL Workbench (Win/*nix, ) Visio (Win only, expensive) PowerDesigner (very powerful and very expensive) ERWin (very powerful and very expensive)

Diff Tools Generate DDL by comparing SQL files and/or installed database schema Do not handle DML Tend to be RDBMS specific SQLYog (Win only, MySQL only, fairly cheap *) Toad (bit more expensive) AdeptSQL (Win only, MS SQL only, bit more expensive)

Data synchronisation Find and fix differences in data One way synchronisation is easy Two way synchronisation is tricky Inefficient as in most cases schema changes requires only a few DML statements that can affect a lot of data Only really useable for lookup tables that are fixed between development and production

XML Schema definition Define schema in an RDBMS independent XML format Store which version of the XML schema is used, to be able to compare two versions of the XML to compute the necessary changes Do not handle DML Limited support for various standard and non standard SQL features One XML schema file covers all supported RDBMS

SQL version control Standard VCS work line based to determine diffs Would need an SQL parser in order to work SQL statement based Daversy (Win only, SQLite/Oracle only, limited and buggy and a dead project)

Manual scripting Update script with all necessary changes Watch out when using auto generated DDL, often very convoluted SQL that tries to create temp tables Keep a table in the DB to store which change scripts have been applied already Question: Also maintain an up to date schema file for new installations?

Dependency Hell Native dump tools often handle dependencies Create dependency graph to figure out dependencies and order statements accordingly Create dummy (non referencing) implementations of all referencing database objects and in a second pass replace dummies with actual implementation

Logging DDL and DML PostGreSQL: log_statement mod MYSQL: binarylog with mysqlbinlog util Oracle/DB2: AUDIT/db2audit command Drawback: Large change scripts that need to be manually optimized to reduce the required statements Alternative approach: Write all DDL and DML to a log and only execute changes from the log Use MySQL Proxy to write log automatically based on a comment in the SQL, but what happens if its forgotten?

Organize DDL and DML Ordered list of DDL and DML changes Dependency order follows from log Necessary DML follows from log Every change has a unique name per release, code to detect if the change is required and potentially a rollback script

Logging DDL and DML LOG CREATE TABLE phone_nums (user_id INT REFERENCES users, phone_num INT) ALTER TABLE phone_nums MODIFY phone_num CHAR(20) DIFF ALTER TABLE users DROP COLUMN phone_num CREATE TABLE phone_nums (user_id INT REFERENCES users, phone_num CHAR(20)) INSERT INTO phone_nums SELECT user_id, phone_num FROM users ALTER TABLE users DROP COLUMN phone_num

Logging DDL and DML Final Change Script CREATE TABLE phone_nums (user_id INT REFERENCES users, phone_num CHAR(20)) INSERT INTO phone_nums SELECT user_id, phone_num FROM users ALTER TABLE users DROP COLUMN phone_num

Migrations RDBMS independent API to help in schema changes More readable than full blown SQL statements For many changes, rollback scripts can automatically be provided Fallback to native SQL when necessary Supports both DDL and DML

Doctrine Migrations Generates PHP files with migration script code comparing the current model classes with the changed schema file./doctrine generate-migrations-diff Migrate the database to the current version./doctrine migrate Automatic up/down handling

Multiple live versions Leave current schema unchanged Create a new schema with all the new tables, columns Create (materialized) VIEW s to pull in the data from the old schema Alternatively, migrate all data to the new schema and recreate the old tables via VIEW s This gets messy quickly and not all operations work on VIEWs

Some tipps Plan ahead to minimize changes ;-) Explicitly hard code columns, do not use SELECT *.. Store grants statements with object definitions MySQL only syntax for version dependent new optinal features: /*!50100 PARTITION.. */ Many RDBMS (Oracle, MySQL..) do an implicit commit after every DDL, some do not (MS SQL, PostgreSQL..) Show list of statements before execution via some magic frontend for additional comfort

References SQLYog Toad MySQL Workbench AdeptSQL Sybase Powerdesigner ERWin Visio

References PostGreSQL logging MySQL logging MySQL Proxy Oracle logging DB2 logging

References ADODB xml-schema ezc/databaseschema PEAR::MDB2_Schema DBDeploy LiquiBase SCM for databases? Doctrine Migrations

Thank you! Questions? Comments? Lukas Smith - lukas@liip.ch CodeWorks 2009 - PHP on the ROAD