Skip to content

Commit

Permalink
memset()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwdeitch committed Jul 25, 2017
1 parent ff8b630 commit 1b04943
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ usage: pg_migrate -H postgres://URI [options]... dir


example usage:
`pg_migrate -H postgres://postgres:pass@localhost:5432 -p -d .`
> pg_migrate -H postgres://postgres:pass@localhost:5432 -p -d .
simulate an up migration for everything in this directory tree

Installation

Download: https://github.com/jwdeitch/pg_migrate/releases/tag/1.0.1
and move to /usr/local/bin/:
`curl -L https://github.com/jwdeitch/pg_migrate/releases/download/1.0.1/pg_migrate -o pg_migrate && mv pg_migrate /usr/local/bin/`
> curl -L https://github.com/jwdeitch/pg_migrate/releases/download/1.0.1/pg_migrate -o pg_migrate && mv pg_migrate /usr/local/bin/

** The release binary is compiled against amd64 linux (ubuntu) and therefore will only work on that system architecture. You may download source and `make build` to compile locally.

Before first run, you must provision the database by running pg_migrate with the -g and -H flags. This is to create the `public.pg_migrate` table, which stores information about which migrations have been ran:
`pg_migrate -H postgres://postgres:pass@localhost:5432 -g`
Before first run, you must provision the database by running pg_migrate with the -g and -H flags. This is to create the "public.pg_migrate" table, which stores information about which migrations have been ran:
> pg_migrate -H postgres://postgres:pass@localhost:5432 -g

Notes

Expand Down
3 changes: 3 additions & 0 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
char **missing_from_db(char **dbList, struct fs_discovered_migrations *fsList) {
int fsi = 0;
char **list = malloc(1000 * sizeof(char *));
memset(list, 0, 1000 * sizeof(char *));
if (list == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand All @@ -25,6 +26,7 @@ char **missing_from_db(char **dbList, struct fs_discovered_migrations *fsList) {
}
if (!located) {
list[filesLocated] = (char *) malloc(PATH_MAX + 1);
memset(list[filesLocated], 0, PATH_MAX + 1);
if (list[filesLocated] == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand All @@ -35,6 +37,7 @@ char **missing_from_db(char **dbList, struct fs_discovered_migrations *fsList) {
fsi++;
}
list[filesLocated] = (char *)malloc(PATH_MAX + 1);
memset(list[filesLocated], 0, PATH_MAX + 1);
if (list[filesLocated] == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
*/
int c = 0, u = 0, d = 0, s = 0, g = 0, p = 0, H = 0;
char *connStr = (char *) malloc(PATH_MAX * sizeof(connStr));
memset(connStr, 0, PATH_MAX * sizeof(connStr));
if (connStr == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand Down
5 changes: 5 additions & 0 deletions src/pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ char **getMigrationsFromDb(PGconn *connection) {
int rows = PQntuples(res);

char **list = malloc(1000 * sizeof(char *));
memset(list, 0, 1000 * sizeof(char *));
if (list == NULL) {
PQfinish(connection);
printf("malloc failed\n");
Expand All @@ -102,6 +103,7 @@ char **getMigrationsFromDb(PGconn *connection) {
int i = 0;
for (; i < rows; i++) {
list[i] = (char *) malloc(PATH_MAX + 1);
memset(list[i], 0, PATH_MAX + 1);
if (list[i] == NULL) {
PQfinish(connection);
printf("malloc failed\n");
Expand All @@ -110,6 +112,7 @@ char **getMigrationsFromDb(PGconn *connection) {
strcpy(list[i], strdup(PQgetvalue(res, i, 0)));
}
list[i + 1] = (char *) malloc(PATH_MAX + 1);
memset(list[i + 1], 0, PATH_MAX + 1);
if (list[i + 1] == NULL) {
PQfinish(connection);
printf("malloc failed\n");
Expand Down Expand Up @@ -154,6 +157,7 @@ void runMigrations(PGconn *connection, char **migrationsToBeRan, int should_simu
}

char *fileContents = malloc(fsize + 1);
memset(fileContents, 0, fsize + 1);
if (fileContents == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand Down Expand Up @@ -251,6 +255,7 @@ void rollbackMigrations(PGconn *connection, int should_simulate) {

if (should_simulate == 0) {
char *fileContents = malloc(fsize + 1);
memset(fileContents, 0, fsize + 1);
if (fileContents == NULL) {
printf("malloc failed to allocate\n");
exit(1);
Expand Down

0 comments on commit 1b04943

Please sign in to comment.