Skip to content
This repository
Jean-Philippe Boily April 03, 2014
file 44 lines (38 sloc) 1.628 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
module QC
  module Setup
    Root = File.expand_path("../..", File.dirname(__FILE__))
    SqlFunctions = File.join(Root, "/sql/ddl.sql")
    CreateTable = File.join(Root, "/sql/create_table.sql")
    DropSqlFunctions = File.join(Root, "/sql/drop_ddl.sql")
    UpgradeTo_3_0_0 = File.join(Root, "/sql/update_to_3_0_0.sql")
    DowngradeTo_3_0_0 = File.join(Root, "/sql/downgrade_from_3_0_0.sql")

    def self.create(c = QC::default_conn_adapter.connection)
      conn = QC::ConnAdapter.new(c)
      conn.execute(File.read(CreateTable))
      conn.execute(File.read(SqlFunctions))
      conn.disconnect if c.nil? #Don't close a conn we didn't create.
    end

    def self.drop(c = QC::default_conn_adapter.connection)
      conn = QC::ConnAdapter.new(c)
      conn.execute("DROP TABLE IF EXISTS queue_classic_jobs CASCADE")
      conn.execute(File.read(DropSqlFunctions))
      conn.disconnect if c.nil? #Don't close a conn we didn't create.
    end

    def self.update(c = QC::default_conn_adapter.connection)
      conn = QC::ConnAdapter.new(c)
      conn.execute(File.read(UpgradeTo_3_0_0))
      conn.execute(File.read(DropSqlFunctions))
      conn.execute(File.read(SqlFunctions))
    end

    def self.update_to_3_0_0(c = QC::default_conn_adapter.connection)
      conn = QC::ConnAdapter.new(c)
      conn.execute(File.read(UpgradeTo_3_0_0))
      conn.execute(File.read(DropSqlFunctions))
      conn.execute(File.read(SqlFunctions))
    end

    def self.downgrade_from_3_0_0(c = QC::default_conn_adapter.connection)
      conn = QC::ConnAdapter.new(c)
      conn.execute(File.read(DowngradeTo_3_0_0))
    end
  end
end
Something went wrong with that request. Please try again.