func AddUserToContainer(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
	  ALTER TABLE containers
		ADD COLUMN process_user text DEFAULT '';
	`)
	return err
}
func ReplaceBuildEventsIDWithEventID(tx migration.LimitedTx) error {
	_, err := tx.Exec(`ALTER TABLE build_events ADD COLUMN event_id integer`)
	if err != nil {
		return err
	}

	startIDs := map[int]int{}

	rows, err := tx.Query(`
		SELECT build_id, min(id)
		FROM build_events
		GROUP BY build_id
	`)
	if err != nil {
		return err
	}

	for rows.Next() {
		var buildID, id int
		err := rows.Scan(&buildID, &id)
		if err != nil {
			return err
		}

		startIDs[buildID] = id
	}

	err = rows.Close()
	if err != nil {
		return err
	}

	for buildID, id := range startIDs {
		_, err := tx.Exec(`
			UPDATE build_events
			SET event_id = id - $2
			WHERE build_id = $1
		`, buildID, id)
		if err != nil {
			return err
		}
	}

	_, err = tx.Exec(`ALTER TABLE build_events DROP COLUMN id`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`ALTER TABLE build_events ALTER COLUMN event_id SET NOT NULL`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`CREATE UNIQUE INDEX build_events_build_id_event_id ON build_events (build_id, event_id)`)
	if err != nil {
		return err
	}

	return nil
}
Exemple #3
0
func initial(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
    CREATE TABLE pull_requests (
        owner      text NOT NULL,
        repository text NOT NULL,
        sha        text NOT NULL
    );
	`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`
    CREATE UNIQUE INDEX pull_requests_unique ON pull_requests (
      owner,
      repository,
      sha
    );
	`)
	if err != nil {
		return err
	}

	return nil
}
func AddIndexesToABunchOfStuff(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		CREATE INDEX build_inputs_build_id_versioned_resource_id ON build_inputs (build_id, versioned_resource_id);
	`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`
		CREATE INDEX build_outputs_build_id_versioned_resource_id ON build_outputs (build_id, versioned_resource_id);
	`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`
		CREATE INDEX builds_job_id ON builds (job_id);
	`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`
		CREATE INDEX jobs_pipeline_id ON jobs (pipeline_id);
	`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`
		CREATE INDEX resources_pipeline_id ON resources (pipeline_id);
	`)

	return nil
}
func DropCompletedFromBuildPreparation(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
	ALTER TABLE build_preparation
	DROP COLUMN completed
	`)
	return err
}
func RemoveVolumesWithExpiredWorkers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
	DELETE FROM volumes v
	WHERE (SELECT COUNT(name) FROM workers w WHERE w.name = v.worker_name) = 0;
	`)
	return err
}
func CleanUpMassiveUniqueConstraint(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE containers
		DROP CONSTRAINT IF EXISTS containers_worker_name_resource_id_check_type_check_source__key
	`)
	return err
}
func MakeVolumesExpiresAtNullable(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE volumes
		ALTER COLUMN expires_at DROP NOT NULL;
	`)
	return err
}
Exemple #9
0
func (d dbVersion) createTable(tx migration.LimitedTx) error {
	_, err := tx.Exec(d.CreateSQL)
	if err == nil {
		err = d.set(tx, 0)
	}
	return err
}
func AddStepLocationToContainers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE containers ADD COLUMN step_location integer DEFAULT 0;
	`)

	return err
}
func AddWorkingDirectoryToContainers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE containers ADD COLUMN working_directory text;
	`)

	return err
}
func CascadePipelineDeletes(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE build_events DROP CONSTRAINT build_events_build_id_fkey;
		ALTER TABLE build_events ADD CONSTRAINT build_events_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds (id) ON DELETE CASCADE;

		ALTER TABLE build_outputs DROP CONSTRAINT build_outputs_build_id_fkey;
		ALTER TABLE build_outputs ADD CONSTRAINT build_outputs_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE;

		ALTER TABLE build_outputs DROP CONSTRAINT build_outputs_versioned_resource_id_fkey;
		ALTER TABLE build_outputs ADD CONSTRAINT build_outputs_versioned_resource_id_fkey FOREIGN KEY (versioned_resource_id) REFERENCES versioned_resources(id) ON DELETE CASCADE;

		ALTER TABLE build_inputs DROP CONSTRAINT build_inputs_build_id_fkey;
		ALTER TABLE build_inputs ADD CONSTRAINT build_inputs_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE;

		ALTER TABLE build_inputs DROP CONSTRAINT build_inputs_versioned_resource_id_fkey;
		ALTER TABLE build_inputs ADD CONSTRAINT build_inputs_versioned_resource_id_fkey FOREIGN KEY (versioned_resource_id) REFERENCES versioned_resources(id) ON DELETE CASCADE;

		ALTER TABLE jobs_serial_groups DROP CONSTRAINT fkey_job_id;
		ALTER TABLE jobs_serial_groups ADD CONSTRAINT fkey_job_id FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE;

		ALTER TABLE builds DROP CONSTRAINT fkey_job_id;
		ALTER TABLE builds ADD CONSTRAINT fkey_job_id FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE;

		ALTER TABLE versioned_resources DROP CONSTRAINT fkey_resource_id;
		ALTER TABLE versioned_resources ADD CONSTRAINT fkey_resource_id FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE;

		ALTER TABLE resources DROP CONSTRAINT resources_pipeline_id_fkey;
		ALTER TABLE resources ADD CONSTRAINT resources_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines(id) ON DELETE CASCADE;

		ALTER TABLE jobs DROP CONSTRAINT jobs_pipeline_id_fkey;
		ALTER TABLE jobs ADD CONSTRAINT jobs_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines (id) ON DELETE CASCADE;
  `)

	return err
}
func AddEnvVariablesToContainers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE containers ADD COLUMN env_variables text NOT NULL DEFAULT '[]';
	`)

	return err
}
Exemple #14
0
// DefaultRegion will insert a default region into the database with the
// name "default", no start, and no end time.
func (m Migrator) DefaultRegion(tx migration.LimitedTx) error {
	_, err := tx.Exec(
		`INSERT INTO regions(name) VALUES(?)`,
		"default",
	)
	return err
}
func AddModifiedTimeToBuildInputs(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE build_inputs
		ADD COLUMN modified_time timestamp NOT NULL DEFAULT now();
`)
	return err
}
func ResetPendingBuilds(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
	UPDATE builds
	SET scheduled = false
	WHERE scheduled = true AND status = 'pending'
	`)
	return err
}
func AddCheckTypeAndCheckSourceToContainers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE containers ADD COLUMN check_type text;
		ALTER TABLE containers ADD COLUMN check_source text;
	`)

	return err
}
func AddCompositeUniqueConstraintToVolumes(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
    ALTER TABLE volumes DROP CONSTRAINT volumes_handle_key;
    ALTER TABLE volumes ADD UNIQUE (worker_name, handle);
	`)

	return err
}
func AddAdminToTeams(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
          ALTER TABLE teams
          ADD COLUMN admin bool DEFAULT false;
      `)

	return err
}
func AddResourceTypesToWorkers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`ALTER TABLE workers ADD COLUMN resource_types text`)
	if err != nil {
		return err
	}

	return nil
}
Exemple #21
0
func createVersionTable(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		CREATE TABLE simple_queue_version (
			version INTEGER
		);
		INSERT INTO simple_queue_version (version) VALUES (0)`)
	return err
}
func RemoveTransitionalCurrentVersions(tx migration.LimitedTx) error {
	_, err := tx.Exec("DROP TABLE transitional_current_versions")
	if err != nil {
		return err
	}

	return nil
}
Exemple #23
0
func AddConfig(tx migration.LimitedTx) error {
	_, err := tx.Exec(`CREATE TABLE config (config text NOT NULL)`)
	if err != nil {
		return err
	}

	return nil
}
func AddHijackURLToBuilds(tx migration.LimitedTx) error {
	_, err := tx.Exec(`ALTER TABLE builds ADD COLUMN hijack_url varchar(255)`)
	if err != nil {
		return err
	}

	return nil
}
Exemple #25
0
func DropLocks(tx migration.LimitedTx) error {
	_, err := tx.Exec("DROP TABLE locks")
	if err != nil {
		return err
	}

	return nil
}
func AddLastCheckedAndCheckingToResourceTypes(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE resource_types
		ADD COLUMN last_checked timestamp NOT NULL DEFAULT 'epoch',
		ADD COLUMN checking bool NOT NULL DEFAULT false
	`)
	return err
}
Exemple #27
0
// createVersionTable creates the version table and inserts the
// initial value (0) into the database.
func createVersionTable(tx migration.LimitedTx) error {
	_, err := tx.Exec("CREATE TABLE migration_version ( version INTEGER )")
	if err != nil {
		return err
	}
	_, err = tx.Exec("INSERT INTO migration_version (version) VALUES (0)")
	return err
}
func ResetCheckOrder(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
	UPDATE versioned_resources
	SET check_order = id
	WHERE check_order != id
	`)
	return err
}
Exemple #29
0
func CreatePipes(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		CREATE TABLE pipes (
			id text PRIMARY KEY,
			url text
		)
	`)
	return err
}
func AddHttpProxyHttpsProxyNoProxyToWorkers(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
		ALTER TABLE workers
		ADD COLUMN http_proxy_url text,
		ADD COLUMN https_proxy_url text,
		ADD COLUMN no_proxy text
	`)
	return err
}