diff --git a/src/migration/migrations/2021-08-03T021418Z_DropAuthGroups.go b/src/migration/migrations/2021-08-03T021418Z_DropAuthGroups.go new file mode 100644 index 00000000..60b8703e --- /dev/null +++ b/src/migration/migrations/2021-08-03T021418Z_DropAuthGroups.go @@ -0,0 +1,66 @@ +package migrations + +import ( + "context" + "time" + + "git.handmade.network/hmn/hmn/src/migration/types" + "git.handmade.network/hmn/hmn/src/oops" + "github.com/jackc/pgx/v4" +) + +func init() { + registerMigration(DropAuthGroups{}) +} + +type DropAuthGroups struct{} + +func (m DropAuthGroups) Version() types.MigrationVersion { + return types.MigrationVersion(time.Date(2021, 8, 3, 2, 14, 18, 0, time.UTC)) +} + +func (m DropAuthGroups) Name() string { + return "DropAuthGroups" +} + +func (m DropAuthGroups) Description() string { + return "Drop the auth groups table, and related tables" +} + +func (m DropAuthGroups) Up(ctx context.Context, tx pgx.Tx) error { + _, err := tx.Exec(ctx, ` + DROP TABLE handmade_user_projects; + CREATE TABLE handmade_user_projects ( + user_id INT NOT NULL REFERENCES auth_user (id) ON DELETE CASCADE, + project_id INT NOT NULL REFERENCES handmade_project (id) ON DELETE CASCADE, + PRIMARY KEY (user_id, project_id) + ); + + INSERT INTO handmade_user_projects (user_id, project_id) + SELECT agroups.user_id, pg.project_id + FROM + handmade_project_groups AS pg + JOIN auth_group AS ag ON ag.id = pg.group_id + JOIN auth_user_groups AS agroups ON agroups.group_id = ag.id; + `) + if err != nil { + return oops.New(err, "failed to recreate handmade_user_projects") + } + + _, err = tx.Exec(ctx, ` + DROP TABLE auth_group_permissions; + DROP TABLE auth_user_groups; + DROP TABLE handmade_project_groups; + + DROP TABLE auth_group; + `) + if err != nil { + return oops.New(err, "failed to drop group-related tables") + } + + return nil +} + +func (m DropAuthGroups) Down(ctx context.Context, tx pgx.Tx) error { + panic("Implement me") +} diff --git a/src/migration/todo.txt b/src/migration/todo.txt index 553280f8..1168f260 100644 --- a/src/migration/todo.txt +++ b/src/migration/todo.txt @@ -1,10 +1,7 @@ Clean this up once we get the website working --------------------------------------------- TODO: Questionable db tables that we inherited from Django: -* auth_group -* auth_group_permissions * auth_permission -* auth_user_groups * auth_user_user_permissions * django_admin_log * django_content_type diff --git a/src/templates/src/blog_index.html b/src/templates/src/blog_index.html index 2b37f199..2972fdb2 100644 --- a/src/templates/src/blog_index.html +++ b/src/templates/src/blog_index.html @@ -3,36 +3,44 @@ {{ define "content" }}
{{/* TODO: Breadcrumbs, or some other link back to the blog index */}} -{{ range .Posts }} -